Zero Sum Game
If you know what you are doing, you can't lose at Tic-Tac-Toe. If your opponent knows what they are doing, you can't win at Tic-Tac-Toe. The game is a zero sum game. If both players are playing with an optimal strategy, every game will end in a tie.
Surpisingly few people know optimal Tic-Tac-Toe stategy. Yes there are some people (and computers) that you will never beat, but they are relatively rare. Knowing this, you can become a Tic-Tac-Toe master.
Before getting started, open a Tic-Tac-Toe playing board in a new browser window so that you can experiment while you read this article.
Players
There are four player types in Tic-Tac-Toe.
- The Novice player makes random moves
- The Intermediate player will blocks their opponent from winning
- The Experienced player knows that playing in certain first squares will lose the game
- The Expert player will never lose
Pitting these players against each other, you can see that in all cases, the better player wins more.
Player Two | |||||
---|---|---|---|---|---|
Novice | Intermediate | Experienced | Expert | ||
Player One | Novice | 1 wins: 57.1% 2 wins: 30.6% Ties: 12.3% |
1 wins: 6.40% 2 wins: 68.3% Ties: 25.3% |
1 wins: 2.60% 2 wins: 76.4% Ties: 21.0% |
1 wins: 0.00% 2 wins: 79.6% Ties: 20.4% |
Intermediate | 1 wins: 90.4% 2 wins: 1.60% Ties: 8.00% |
1 wins: 31.6% 2 wins: 17.1% Ties: 51.3% |
1 wins: 16.1% 2 wins: 10.3% Ties: 73.6% |
1 wins: 0.00% 2 wins: 16.1% Ties: 83.9% |
|
Experienced | 1 wins: 90.8% 2 wins: .700% Ties: 8.50% |
1 wins: 35.5% 2 wins: 11.7% Ties: 52.8% |
1 wins: 13.3% 2 wins: .800% Ties: 85.9% |
1 wins: 0.00% 2 wins: 1.70% Ties: 98.3% |
|
Expert | 1 wins: 97.8% 2 wins: 0.00% Ties: 2.20% |
1 wins: 76.6% 2 wins: 0.00% Ties: 23.4% |
1 wins: 27.1% 2 wins: 0.00% Ties: 72.9% |
1 wins: 0.00% 2 wins: 0.00% Ties: 100.% |
Expert - The player that can't lose
On the Tic-Tac-Toe game board that you have opened in a new window, choose the "Expert" type for each player and hit "New Game". Verify that the result of each game is a tie (cat's game).
O | X | O |
O | X | X |
X | O | X |
Neither of the computer players can be beaten because they are playing as well as game can be played. The computer does this by playing out every single game of Tic-Tac-Toe ahead of time and figuring out which moves are good and which are bad. The computer can do this because there are not a lot of possible games. The first move can be played in any of nine squares, the second in any of eight squares, the third in any of seven squares and so on. That means there are at most nine factorial or 362,880 possible games. A computer can breeze though 400,000 games in a blink of an eye. In reality, it has to play far fewer games than that. There are only 125,168 games of Tic-Tac-Toe because somebody wins most of them before all off the squares have been filled. The Tic-Tac-Toe is symetrical and if the computer can realize that many games are the same because it could rotate the board, there are even fewer games than that. Suffice to say that computers win through brute force.
So how can a human become unbeatable in Tic-Tac-Toe? A human doesn't even have time to play out one hundred games in the mind and still make a move in a reasonable amount of time. However, a human can compensate with experience and reasoning.
O | X | |
O | X | |
Novice - Stupid random play
Everybody can beat the "Novice" player virtually every game. Set one player to Novice and the other to human and observe how easy it is to beat the novice.
The novice simply places its mark in any empty square. This stategy is very poor and almost never wins.
O | X | |
O | ||
X |
Player | First | Type | Wins | Record |
---|---|---|---|---|
X | 200 | 31.5% | ||
O | 116 | 18.3% | ||
Cat | 319 | 50.2% |
Intermediate - reactionary play
Most Tic-Tac-Toe players start off as reactionary players. Reactionary players will block their opponents three in a row, or take any three in a row that they can. Otherwise, they play like a novice and choose random moves. This style of play is what the "Intermediate" computer player uses.
Experienced - knows how to start
The experienced player knows the best starting moves. The stategies below explain these moves in detail.
Strategies
Move First
If two intermediate players play many games. The player that goes first will win about twice as often as the player that goes second. Verify this for yourself by pitting two intermediate players against each other and watching the stats as you have them play many new games.
On some level this makes sense. There are only nine squares on a Tic-Tac-Toe board, the first player will get five of them but the second player will only get four.
When two experts play, the game always ends in a tie. In all other cases, the player that goes first wins far more than they would have if their opponent had gone first.
Know the bad first moves
Player 1
If you are going first, know the safe first moves. The trick is to avoid the edges. The corners and the center are safe moves:
Player 2
There are two possibilities. Either player 1 took the corner, or the center.
|
|
Player 1 can be ruthless
If player 1 moves in the corner for the first move, player 2 must take the center. If player 1 is playing against a novice, player 1 can be ruthless and always play in the corner first. That leaves a lot of board for novice to choose from and player 1 will win more often.
Become an expert
The first moves (or opening book) are the hardest to figure out. Beyond the first move, it doesn't take much practice to move from being an experienced player to being an expert player. One good way to go about it is to play the fool against a computer expert player and see how you get beaten. Try known bad first moves and see how the compuer can outwit you every time. Beyond this point, I leave becoming an expert as an exercise to the reader.
15 thoughts on “Tic-Tac-Toe Strategy”
I did Expert vs Expert, and sure enough, nobody won. However, strangely, I found that a Novice can beat an Expert about 3% of the time when the Novice goes first, and about 1% of the time when the expert goes first. Why is it that a novice can beat an expert but an expert can lose against a novice?
Results were simulated with 10,000 games using an autoclicker.
If the expert computer moves are instant it must be programmed for each starting move, including all four edges or an edge first move might cause it to not know where to go at one of it’s moves and give the player a free turn then it is possible to beat. Also I’ve yet to discover a scenario where the first move can lose if played correctly regardless of which square is picked first.
Also to explain why expert vs expert is always a tie, that is easier to program for because the moves are more limited.
If the first player takes a corner and the next player takes the center it’s a forgone conclusion it will be a draw. Two expert players means nobody will win. If the first player takes the center then the second player takes a corner. Again nobody can win. If these are the first to squares taken the outcome is inevitable
Corner then centre isn’t quite a forgone conclusion yet. Often if player one then plays the opposite corner, an inexperienced player 2 plays one of the remaining corners and then loses when player 1 takes the 4th corner.
I agree with anonymous’s confusion about the percentage rate of when either The Expert or the Novice goes first, which was within his/her most recent Comment s/he posted on June 3rd. I love Tic-Tac-Toe, but no one ever plays with me. Therefore, I can say that I am Intermediate. I have played with novice people and have seen novice against novice AND novice against expert. The same excact thing happened, and I was baffled when the Novice – Novice (N-N) team barely got any scores, while Team Novice – Expert (N-E) had the N go first (the E was being generous) and the Novice won many more times. It WAS then harder for the E to win (and he got mad about it)! I just wanted to agree with Anonymous because his/her comment really related to my thoughts, and I think other people don’t look strongly to other really important and reinforced thoughts and ideas. :o)
(I also didn’t notice I’m making this comment in 2017 while s/he wrote it in 2015)!!!
I’m confused why the claim is made that there are 9! games possible. I believe the number should be 3^9 (19683).
To take my point consider that each square of the board can either be blank ‘B’, have an ‘X’, or an ‘O’. So a single square can only have 3^1 possible contents. If the board consisted of two squares, then the possible combinations would be BB, BX, BO, XB, XX, XO, OB, OX, OO. That is 9, or 3^2. So for 9 squares the number of possible combinations would be 3^9.
I’d agree that optimized strategy makes for a game that can never be won. I’ve written a program in FreeBasic to try out the matchbox method of machine learning demonstrated in Matt Parker’s video (https://www.youtube.com/watch?v=R9c-_neaxeU) that shows that after a few thousand rounds the computer learns to tie every game.
It is
9!
because the first move has 9 choices of square, then the second 8 choices, the third 7, and so on. There are3^9
game states, but there are more games than that because multiple games can arrive at the same state. That doesn’t take into effect the order in which moves are played. For example consider that there isXOX
in the first row. It could be that X’s first move was in either corner. Game state alone does not tell you that. The order in which moves are made is vitally important in Tic-Tac-Toe. Making moves in the wrong order will lose games.I feel like the intermediate and the experienced groups are the closest in skill level. I ran the test were the intermediate plays first against the experienced. I ran 147 tests. It was a tie in 124 (84.4%) of the tests. the intermediate won 11(7.5%). While the experienced won 12 (8.2%).
I once saw the closeness of this as well and decided to run some games, but more than 147. When you press the “new game” button, and then HOLD down “enter” on your keyboard, it simulates games at a very fast rate. After a while I was too tired of holding down the enter key with my finger, so I used a Nintendo DS to hold down the enter key (it weighs enough to constantly keep the button pressed down). After a few minutes, I checked on it to see how it was doing, and I saw that it has simulated, and was still simulating, thousands of games, so I decided to check on it again later.
I forgot to check it again until the next morning.
After an unprecedented 1,109,927 games, intermediate won 165,022 times (14.87%), experienced won 122,875 times (11.07%), and there were 822,030 ties (74.06%). The more games you simulate, the closer you get to these percentages.
I know this is an old post on this blog, but I’m wondering why you say that edges are not safe as first move? By starting on an edge, just like starting in the center, the opponent have only four right choices to not lose automatically. I would even go as far and say that edges are even better because most novices and intermediate players learn to counter the corner and center strategies, but are alien to the edge strategy which seems to be more niche.
This is the pattern for edges:
· • •
› · ·
· • •
› represents the start move
• represents the losing move for the opponent
There are many ways to force a win if your opponent starts on an edge. Trust me, whenever does an edge for their first move they always lose the game if playing against an optimal player. There are a lot of opportunities for a corner player to win. This is an insight that will come after you’ve played hundreds/thousands of tic tac toe games. The edges let the opponent control a large portion of the possible win states.
I once saw the closeness of this as well and decided to run some games, but more than 147. When you press the “new game” button, and then HOLD down “enter” on your keyboard, it simulates games at a very fast rate. After a while I was too tired of holding down the enter key with my finger, so I used a Nintendo DS to hold down the enter key (it weighs enough to constantly keep the button pressed down). After a few minutes, I checked on it to see how it was doing, and I saw that it has simulated, and was still simulating, thousands of games, so I decided to check on it again later.
I forgot to check it again until the next morning.
After an unprecedented 1,109,927 games, intermediate won 165,022 times (14.87%), experienced won 122,875 times (11.07%), and there were 822,030 ties (74.06%). The more games you simulate, the closer you get to these percentages.
I can stalemate Expert level every time starting on edge. There is no increased chance of losing, but there is a decreased change of winning, because opening side moves have 1 more safe counter move than a center opening move.
If you play the simulator enough times you will see that there is a stalemate path for any opening move. The goal of the game is to set up a double trap. Off of the top of my head there are 5 shapes you can create on the board that result in a double trap.
All you need to do to avoid losing is block the opponent from setting up a double trap. If they open in center, you play a corner. If they open in corner, you play center. If they open on a side, you play any of the 3 squares adjacent to them, or the one opposite them. After the first move, just block them from creating one of the five shapes that set up a double trap, or block any 2 consecutive pieces.
I implemented my own Tic Tac Toe strategy and benchmarked it against a purely random player starting 50% of the games. When simulating 100,000 games it achieves about 88.5% wins with the rest being ties. I am curious: Do you know what the best possible win rate is against a purely random player? Have you benchmarked your ‘expert’ against ‘fully random’?
My export wins 97.8% of the time if it goes first. It wins 79.6% of the time if it goes second. The average of those two is 88.7%, pretty much identical to the results you got. There is a table near the top of this page with that information.