我正在创建一个井字游戏作为具有二维数组的项目,并且在检查点以查看是否有赢家时遇到了一些麻烦。有人可以帮我调试吗?这里是checkwinner函数和main函数。
char CheckWinner( char board[3][3])
{
int i = 0;
int j = 0;
if ( board[i][j] =='X' && board[i][j+1] == 'X' && board[i][j+2]== 'X' )
{ W = X;}
else if (board[i+1][j] && board[i+1][i+1] && board[i+1][j+2]== 'X' )
{ W = X;}
else if (board[i+2][j] && board[i+2][j+1] && board[i+2][j+2]== 'X')
{ W = X;}
else if (board[i][j] && board[i+1][j] && board[i+2][j]== 'X')
{ W = X;}
else if (board[i][j+1] && board[i+1][j+1] && board[i+2][j+1]== 'X')
{ W = X;}
else if (board[i][j+2] && board[i+1][j+2] && board[i+2][j+2]== 'X')
{ W =X;}
else if (board[i][j] && board[i+1][j+1] && board[i+2][j+2]=='X')
{ W = X;}
else if (board[i+2][j] && board[i+1][j+1] && board[i][j+2]== 'X')
{ W = X;}
else if (board[i][j] && board[i][j+1] && board[i][j+2]== 'O' )
{ W = O;}
else if (board[i+1][j] && board[i+1][j+1] && board[i+1][j+2]== 'O')
{ W = O;}
else if (board[i+2][j] && board[i+2][j+1] && board[i+2][j+2]== 'O')
{ W = O;}
else if (board[i][j] && board[i+1][j] && board[i+2][j]== 'O')
{ W = O;}
else if (board[i][j+1] && board[i+1][j+1] && board[i+2][j+1]== 'O')
{ W = O;}
else if (board[i][j+2] && board[i+1][j+2] && board[i+2][j+2]== 'O')
{ W = O;}
else if (board[i][j] && board[i+1][j+1] && board[i+2][j+2]== 'O')
{ W = O;}
else if (board[i+2][j] && board[i+1][j+1] && board[i][j+2]== 'O')
{ W = O;}
return W;
}
int main ()
{
char board[3][3];
char Win = CheckWinner(board);
int r = 0;
InitializeBoard(board);
for (int r = 0; r < 4 ; r++)
{
PlayX(board);
PlayO(board);
PrintBoard(board);
}
CheckWinner(board);
cout << Win ;
if (Win == X)
{
cout << "The winner is Player 1.";
}
else if (Win == O)
{
cout << "The winner is Player 2.";
}
else if (Win == TIE)
{
cout << " IT'S A TIE";
}
else;
system("PAUSE");
return 0;