i'll try to write reversi game.

when i check the program most of functions wroks properly. but when i input test i find some problems. anybody can hrlp me to find the problam? thenks very.

thets my code.

Code:#include <stdio.h> #define size 8 #define WHITE 'W' #define NONE ' ' #define BLACK 'B' void initBoard(char board[size][size]); void printBoard(char board[size][size],int player); void flip(int x1,int y1,int x2,int y2,char board[size][size]); int hasLegitMove(int player,char board[size][size]); int isLegitMove(int player,int x, int y,char board[size][size] ,int makeTheMove); int checkIfLegitDirectionAndColorAndFlipIfNeeded(int player,int i, int j,char board[size][size],int iDir,int jDir,int colorAndflipWhenPossible); void main() { char board[size][size]={"0"}; int player=1, player2=2; int i,j; int winnera=0,winnerb=0; int testerA=1,testerB=1; initBoard(board); while(hasLegitMove(player,board)){ printBoard(board,player); scanf( "%d",&j); scanf( "%d",&i); testerA=1,testerB=1; i=i-1;j=j-1; if(i+1>size || j+1>size || i+1<0 ||j+1<0) { printf( "There is no such square please select a different square \n"); testerA=0; } if(board[i][j]!=NONE &&testerA) { printf( "This square is already full please select a different square\n"); testerB=0; } if(testerA && testerB) { testerA=1; testerB=1; if(isLegitMove(player,i,j,board,0)){ isLegitMove(player,i,j,board,1); if(player==1) player=2; else player=1; } else {printf( "This move is not legitimate\n"); } if(hasLegitMove(player,board)==0) { if(player==1) player2=2; else player2=1; } } } for( j=0;i<size;j++) for( i=0;j<size;i++) { if(board[i][j]==WHITE) winnera++; else winnerb++; } printf( "\nPlayer 1 has %d squares\n",winnera); printf( "Player 2 has %d squares\n",winnerb); if(winnera>winnerb) printf( "player 1 wins !!!!\n"); if(winnerb>winnera) printf( "player 2 wins !!!!\n"); if(winnerb==winnera) printf( "Its a tie !!!!!!\n"); } void initBoard(char board[size][size]) { int i,j; for( i=0;i<size;i++) for( j=0;j<size;j++) { board[i][j]= NONE; } board[size/2-1][size/2-1]= WHITE; board[size/2][size/2]= WHITE; board[size/2-1][size/2]= BLACK; board[size/2][size/2-1]= BLACK; } void printBoard(char board[size][size], int player) { int i,i2, j; printf( "player %ds turn\n \n",player); printf( " "); for ( i=1; i < size+1; i++ ) printf("%d|", i); printf( "\n"); printf( " "); for ( i=0; i < size-1; i++ ) { printf("--"); } printf( "--\n"); for ( i=0; i < size; i++ ) { i2=i+1; printf( "%d|", i2); for ( j=0; j < size; j++ ) { switch ( board[j][i] ) { case BLACK: printf("B"); break; case WHITE: printf("W"); break; case NONE : printf(" "); break; } printf( "|"); } printf( "\n"); if ( i < size ) { printf( " "); for ( j=0; j < size-1; j++ ) { printf( "--"); } printf( "--\n"); } } } void flip(int x1,int y1,int x2,int y2,char board[size][size]){ int x,y,i; char changer=board[x1][y1]; //down if(y1==y2 && x1>x2) { for(x=0;x<size;x++) for(y=0;y<size;y++) if(y==y1 && x>x2 && x<x1) board[x][y]=changer; } //up if(y1==y2 && x2>x1) { for(x=0;x<size;x++) for(y=0;y<size;y++) if(y==y1 && x<x2 && x>x1) board[x][y]=changer; } //left if(x1==x2 && y1>y2) { for(x=0;x<size;x++) for(y=0;y<size;y++) if(x==x1 && y>y2 && y<y1) board[x][y]=changer; } //right if(x1==x2 && y2>y1) { for(x=0;x<size;x++) for(y=0;y<size;y++) if(x==x1 && y>y1 && y<y2) board[x][y]=changer; } //left up if(x1>x2 && y1>y2) { for(i=1;x2+i<x1;i++) board[x2+i][y2+i]=changer; } //right down if(x2>x1 && y2>y1) { for(i=1;x1+i<x2;i++) board[x1+i][y1+i]=changer; } //left down if(x2>x1 && y1>y2) { for(i=1;x1+i<x2;i++) board[x2-i][y2+i]=changer; } //right up if(x1>x2 && y2>y1) { for(i=1;x2+i<x1;i++) board[x1-i][y1+i]=changer; } } int checkIfLegitDirectionAndColorAndFlipIfNeeded(int player,int i, int j,char board[size][size],int iDir,int jDir,int colorAndflipWhenPossible) { char playerdefine; int k; int l; if(player==1) playerdefine=WHITE; if(player==2) playerdefine=BLACK; k=i+iDir; l=j+jDir; if(board[k][l]==playerdefine) return 0; if(k>=0 && k<size && l>=0 && l<size) { if(player==1) while(board[k][l]==BLACK) { k+=iDir; l+=jDir; if(board[k][l]==WHITE){ if(colorAndflipWhenPossible==1) { board[i][j]=playerdefine; flip(i,j,k,l,board); } return 1; } } if(player==2) while(board[k][l]==WHITE) { k=k+iDir; l=l+jDir; if(board[k][l]==BLACK){ if(colorAndflipWhenPossible==1) { board[i][j]=playerdefine; flip(i,j,k,l,board); } return 1; } } return 0;} return 0; } int isLegitMove(int player,int x, int y,char board[size][size] ,int makeTheMove) { int countLegit=0,i,j; if(board[x][y]!=NONE) return 0; for(i=-1;i<=1;i++) for(j=-1;j<=1;j++) if(i!=0 || j!=0){ countLegit+=checkIfLegitDirectionAndColorAndFlipIfNeeded(player,x,y,board,i,j,makeTheMove);} return countLegit; } int hasLegitMove(int player,char board[size][size]){ int i,j; for(i=0;i<size;i++) for(j=0;j<size;j++) if(board[i][j]==NONE && isLegitMove(player,i,j,board,0)) return 1; return 0; }