-3

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

1 Answers1

2

Actually, the game requires very little depth. Priorities for any position are:

  1. Check for a winning move and make it
  2. Check for opponent win on next turn and block it
  3. Take the center
  4. Take an open corner
  5. Take an open side

By valuing sides over corners, you're going to lose some games.

Prune
  • 76,765
  • 14
  • 60
  • 81
  • Exactly, that's what i did with evaluating each node, that's what the code above does, it gives each node a value with which the minimax should work. If X controls a corner, add 1 to the value of the node, if O controls a corner, subtract 1 from the value. If X controls the center, add 4, if O controls it subtract 4. If X won add 20 - The number of spots taken on the board, and if O won subtract the same value. – Lazar Vuckovic Nov 29 '17 at 20:33
  • And it does require depth so it can predict moves that will later lead to the win of your opponent – Lazar Vuckovic Nov 29 '17 at 20:35