2次元配列のプロジェクトとして三目並べのゲームを作成していますが、勝者がいるかどうかを確認するためにスポットをチェックするのに問題があります。誰かが私がこれをデバッグするのを手伝ってもらえますか?これが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;