我决定制作一个井字游戏的 C 程序。我现在正试图让 AI 无敌,但我遇到了一个问题。
我写了这个:
int getFutureScoreOfMove(char square[][columns], char turn)
{
int row, column, curBestScore, score;
if(turn == 'C') curBestScore = -100;
else curBestScore = 100;
for(i = 0; i < 3; i ++)
{
for(j = 0; j < 3; j++)
{
if(square[i][j] == ' ')
{
if(turn == 'C')
{
square[i][j] = 'X';
score = getFutureScoreOfMove(board, 'U');
square[i][j] = ' ';
}
else
{
square[i][j] = 'O';
score = getFutureScoreOfMove(board, 'C');
square[i][j] = ' ';
}
if(turn == 'C' && score > curBestScore) curBestScore = score;
if(turn == 'U' && score < curBestScore) curBestScore = score;
}
}
}
return(curBestScore);
}
代码有问题,因为它不是无敌的人工智能,而且是无效的。为什么?我该如何解决?
谢谢 :)