I have decided to make a C program of Tic-Tac-Toe. I am trying to make the AI invincible at the moment but I have encountered a problem.
And I wrote this:
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);
}
There is something wrong in the code, as it is NOT invincible AI, and is ineffective. Why? And how can I fix it?
Thank you :)