255,168 ways of playing Tic Tac Toe

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).

 

  • This is an exercise in examining the objective properties of a game. There are two interesting sides to this:
  • 1) The objective properties of Tic Tac Toe really matter for our enjoyment of it: It is a boring game because there are so relatively few combinations.
  • 2) On the other hand, humans clearly play the game in a different way than the computer. The computer’s playing style lets us make some observations about how humans play games.
  • To the computer, the first move is the most complicated (takes around a second on my 2ghz machine). This is unlike human players who seldomly have any problem deciding what to do on the first move.
  • The program assumes that the opponent does not make any mistakes. Humans do make mistakes, of course, so adding some amount of randomness in algorithm would probably make it a better player against human opponents.
  • The number of possible unique games is larger than I would have guessed, but this indicates how we humans are very good at identifying patterns. Faced with the huge number of variations in a game like this, we simply identify some general properties of Tic Tac Toe: Beginning in the middle is a good thing; if your opponent begins in the middle, you must pick the corner; a good way of winning is to threaten two squares simultaneously.
  • We think about games like this in fuzzy and chaotic ways – this gives us a lot of flexibility.
  • It is the same fuzziness that leads us into making stupid mistakes.
  • On some level, it is our fuzzy way of playing games that allows us to have fun. If we simply played with the unimaginative brute force strategy that the computer uses, it would definitely be work rather than play – and nobody would have any fun playing against us, for that matter.

65 thoughts on “255,168 ways of playing Tic Tac Toe”

  1. I beat it. I let the computer go first. He chose the left side. I went mid. He chose top left corner. I went bottom left. He chose right side. I went top right corner and game over. It was the second time I played it. The first time I went first and it was a tie.

  2. I’ve beaten it twice more. It happens whenever the computer goes first and chooses one of the sides as opposed to one of the corners or the mid. I was o’s it was x’s. The last time I beat it, it chose the left side. I went mid. It chose top right corner. I went bottom mid. It went bot left corner. I went top and it was a win. I screenshoted it this time. I can send it to you if you’d like.

  3. Hey, I was working on a tic tac toe playing algorithm, and just for fun implemented a function that counts the amount of games possible after x moves. I got a different result from you, and it’s backed up by this http://www.se16.info/hgb/tictactoe.htm, and I assume you made a mistake. How did you count the positions? I would like to discuss that with you, also if you got it wrong it would be nice to fix if as you are the first site when I searched this topic.

Leave a Reply

Your email address will not be published. Required fields are marked *