Tic Tac Toe (noughts and crosses) is always such a nice example.

I was thinking about strategies and decided to implement a program that plays Tic Tac Toe according to John von Neumann’s minimax. This is a kind of meta-strategy that can be used for playing any game: Always chose the move that will minimize the maximum damage that your opponent can do to you.

The algorithm works recursively by looking for the move that will let an optimally playing opponent inflict the least damage. The opponent’s strategy is calculated by way of the same algorithm, and so on. This means that on the first move, the computer investigates the entire game tree – it considers every single possible Tic Tac Toe game and then choses randomly among the best (least dangerous) moves.

Have a go at http://www.half-real.net/tictactoe/

Here’s a document with every single game of Tic Tac Toe. It gives the following numbers.



255,168 unique games of Tic Tac Toe to be played. Of these, 131,184 are won by the first player, 77,904 are won by the second player, and 46,080 are drawn.



This supports the intuition that it is an advantage to begin the game.



These numbers do not take similar board positions into account – rotating the board, mirroring it and so on. It does not matter which corner you place the first piece in, but this is not taken into account here.



If neither player makes a mistake, the game is drawn (but we knew that already).