So, my assignment was to think of a good evaluation function so that the Tic Tac Toe AI we have designed using the Minimax algorithm would be unbeatable. The limits we had were to not change the source code for the rest of the game, and that the lowest depth of the game tree at which the AI was supposed to function flawlessly had to be 3. For example, calling the minimax function with a depth of 3 should work the same as calling it with the depth of 8. My question is, can a tic tac toe AI even function with that shallow of a depth? This was my algorithm, but it was flawed, seeing as it was beaten in some very specific cases.
public int Evaluate()
{
int count = 0;
if (CurrentState.Field(0, 0) != 0)
count += (CurrentState.Field(0, 0) == 1) ? 1 : -1;
if (CurrentState.Field(0, 2) != 0)
count += (CurrentState.Field(0, 2) == 1) ? 1 : -1;
if (CurrentState.Field(2, 0) != 0)
count += (CurrentState.Field(2, 0) == 1) ? 1 : -1;
if (CurrentState.Field(2, 2) != 0)
count += (CurrentState.Field(2, 2) == 1) ? 1 : -1;
if (CurrentState.Field(1, 1) != 0)
count += 4 * ((CurrentState.Field(1, 1) == 1) ? 1 : -1);
if (CurrentState.over != 0)
count += (CurrentState.over == 1) ? 20 - Current State.SpotsTaken() : -20 + CurrentState.SpotsTaken();
return count;
}
The idea is that the corners are worth the least "points", but some nonetheless, the center is worth more "points", with winning being worth the most "points". the CurrentState is the state being evaluated, with CurrentState.Field being the game board. The value of a cell of the game board is 0 if the spot is not taken, 1 if there's an X, and 2 if there's an O. CurrentState.over is 1 if the game is over and if the winning player is X, 2 if the winning player was O, and 0 if it's a draw. I've gotten 1 out of 5 points seeing as my game was beaten, just want to see if that's justified.
This is the series of events in which the game doesn't work with a depth of 3