//reprezentarea interna a tablei de joc - //matrice 8x8 de bytes //0 - neocupat //1 - piesa a jucatorului 1 //2 - piesa a jucatorului 2 public class board{ byte[][] mat; public board(){ int i,j; mat=new byte[9][]; for (i=0;i<=8;i++) mat[i]=new byte[9]; //bile default pe tabla mat[4][5]=2;mat[5][4]=2; mat[4][4]=1;mat[5][5]=1; } public board(byte[][] a){ mat=new byte[9][]; for (int i=0;i<=8;i++) mat[i]=new byte[9]; for (int i=1;i<=8;i++) for (int j=1;j<=8;j++) mat[i][j]=a[i][j]; } public board(board b){ mat=new byte[9][]; for (int i=0;i<=8;i++) mat[i]=new byte[9]; for (int i=1;i<=8;i++) for (int j=1;j<=8;j++) mat[i][j]=b.getElementAt(i,j); } public byte getElementAt(int r,int c){ if ((r<1||r>8)||(c<1||c>8)) return -1; else return mat[r][c]; } public byte[][] getMatrix(){ return mat; } public void setElementAt(int r, int c, byte color){ mat[r][c]=color; } public int howMany(){ int ret=0; for (int i=1;i<=8;i++) for (int j=1;j<=8;j++) if (mat[i][j]!=0) ret++; return ret; } public int howManybyColor(int color){ int ret=0; for (int i=1;i<=8;i++) for (int j=1;j<=8;j++) if (mat[i][j]==color) ret++; return ret; } public String toString(){ String ret=""; for (int i=1;i<=8;i++){ ret+="\n"; for (int j=1;j<=8;j++) if (mat[i][j]!=0) ret+=new Byte(mat[i][j]).toString()+" "; else ret+=". "; } return ret; } }