我似乎无法使此功能正常工作。你可以假设,因为我检查了垂直,水平和对角线,如果那些没有获胜,那将是一个平局,但我的程序在我填写左上方框和中间框后说它是一个平局。有什么建议?我是否必须改变搜索垂直水平和对角线的方式?
以下是此功能的代码:
char winningLetter;
for (int i = 0; i < 3; i++)
{
if (board[i][0] == board[i][1] && board[i][1] == board[i][2])
{
winningLetter = board[i][0];
}
}
for (int i = 0; i < 3; i++)
{
if (board[0][i] == board[1][i] && board[1][i] == board[2][i])
{
winningLetter = board[0][i];
}
}
if ((board[0][0] == board[1][1] && board[1][1] == board[2][2]) ||
(board[0][2] == board[1][1] && board[1][1] == board[2][0]))
{
winningLetter == board[1][1];
}
if (winningLetter == 'X')
{
cout << "Player One is the winner!" << endl;
}
else if (winningLetter == 'O')
{
cout << "Player Two is the winner!" << endl;
}
else
{
cout << "The game is a tie!" << endl;
tie = true;
}
return;
答案 0 :(得分:1)
问题在于有一个错误的条件。
条件不是
但
你从未检查游戏是否结束。