By Mian Ali Khalid · Published · How we build and test tools
How to play tic tac toe
- Players take turns placing their mark, X or O, in an empty square of the 3 by 3 grid.
- The first player to get three of their own marks in a row wins. A row can be horizontal, vertical or diagonal, which makes 8 winning lines.
- If all nine squares are filled and nobody has a line, the game is a draw.
To play tic tac toe with the keyboard, press Tab to reach the board, use the arrow keys to move between squares and press Enter or Space to place your mark. Each square announces itself to screen readers, for example "row 2 column 3, empty", and the status line says whose turn it is and how the round ended.
Tic tac toe vs computer: the three levels
| Level | What the computer does | Can you win? |
|---|---|---|
| Easy | Takes a winning move if it has one, otherwise plays a random empty square. | Yes, often. |
| Medium | Takes a winning move if it has one, otherwise blocks your winning move, otherwise plays a random empty square. | Yes, by setting up two threats at once (a fork). |
| Unbeatable | Searches every possible continuation (minimax). It prefers the fastest win and the slowest loss, and chooses at random among equally good moves. | No. The best result is a draw. |
Minimax is a decision rule that minimises the possible loss in the worst case; Wikipedia notes that for two-player zero-sum games it coincides with the Nash equilibrium. Tic tac toe is small enough that the computer can follow it to the end of every game, so the Unbeatable level is not a heuristic.
Tic tac toe 2 player on one device
Choose "2 players, one device" as the opponent. X and O alternate automatically, and the score table switches to X, O and draws. Use "Who moves first" to start with X, start with O, or alternate each round so the starting advantage is shared. There is no online matchmaking: both players must be at the same screen.
Why perfect play always ends in a draw
Wikipedia describes tic tac toe as a solved game, with a forced draw assuming best play from both players, and says that with optimal play the game always ends in a draw. It also says X can win or force a draw from any starting mark (corner, edge or centre), so the first move alone does not decide the game. It adds that a corner opening gives the opponent the fewest squares that avoid losing, and that, against imperfect play, one study found a centre opening best for X.
Wikipedia lists a priority order, from Newell and Simon's 1972 program, that a player can follow to play perfectly: choose the first available move from
- Win: complete your own three in a row.
- Block: stop the opponent from completing a line.
- Fork: create two winning threats at once.
- Block the opponent's fork.
- Centre.
- Opposite corner to the opponent's corner.
- Any empty corner.
- Any empty side.
For the second player, Wikipedia says O must always answer a corner opening with the centre and a centre opening with a corner, and that an edge opening must be answered with the centre, an adjacent corner or the opposite edge.
How many tic tac toe games and positions are there?
These counts come from enumerating every legal sequence of moves with X moving first, stopping when a line is made or the board is full. Boards that are rotations or mirror images are counted separately. The figures come from enumerating every legal move sequence.
| Result | Complete games | Share of all games |
|---|---|---|
| X wins | 131,184 | 51.4% |
| O wins | 77,904 | 30.5% |
| Draw | 46,080 | 18.1% |
| All games | 255,168 | 100% |
The shares count move sequences, not how often real players win, so they say nothing about who wins in practice. There are 5,478 different reachable boards, including the empty one. Wikipedia reports smaller figures for the same game once symmetric boards are merged: 765 essentially different positions and 26,830 possible games, of which 138 end positions split into 91 won by X, 44 won by O and 3 drawn.
| Moves played | Games that end here | Reachable boards with this many marks |
|---|---|---|
| 0 | 0 | 1 |
| 1 | 0 | 9 |
| 2 | 0 | 72 |
| 3 | 0 | 252 |
| 4 | 0 | 756 |
| 5 | 1,440 | 1,260 |
| 6 | 5,328 | 1,520 |
| 7 | 47,952 | 1,140 |
| 8 | 72,576 | 390 |
| 9 | 127,872 | 78 |
The shortest possible game is 5 moves, because the first player needs three marks.
What this tic tac toe game does not do
- It is a 3 by 3 board only. There are no larger boards and no "connect four in a row" variants.
- There is no online multiplayer, matchmaking, chat or accounts. 2 player means two people sharing one screen.
- The score lives in the open page and is lost when you close or reload it.
- The computer plays only the three levels listed above. Easy and Medium are deliberately beatable and do not look ahead.
FAQ
Can you win tic tac toe every time?
No. With correct play from both sides the game is a draw, so the best you can guarantee against a player who never slips is a draw. You can win only when the other side makes a mistake. The Unbeatable level here does not make one, so against it the best result is a draw.
Who goes first in tic tac toe?
There is no universally agreed rule. Wikipedia notes that its article uses the convention that X plays first. Here you choose: you, the computer, or alternate each round, and in 2 player mode you choose X or O or alternate.
How many possible games of tic tac toe are there?
If you count every different sequence of moves until someone wins or the board fills, there are 255,168 games when X moves first: 131,184 won by X, 77,904 won by O and 46,080 drawn. Counting boards that are the same after rotating or flipping as one, Wikipedia gives 26,830 possible games.
Is tic tac toe a solved game?
Yes. Wikipedia describes it as a solved game with a forced draw assuming best play from both players. The game is small enough for a program to check every line of play, which is what the Unbeatable computer here does.
How do I play tic tac toe against the computer?
Choose Computer as the opponent, pick Easy, Medium or Unbeatable, choose whether you play X or O and who moves first, then press a square. Easy takes a win if one is available and otherwise moves at random. Medium also blocks your winning move. Unbeatable never loses.
How do I play tic tac toe with 2 players on one device?
Choose "2 players, one device". The two of you take turns pressing squares on the same screen, X and O alternate automatically, and the score tallies X wins, O wins and draws until you close the page.
Why does the Unbeatable computer not always open the same way?
Several different moves can be equally good, for example any corner as the first move. The computer picks at random among the moves that keep the best possible result, so games vary but it still never loses.
Is tic tac toe the same as noughts and crosses?
Yes. Noughts and crosses is the name used in Commonwealth English, and Wikipedia also lists Xs and Os for Canadian or Irish English. The rules are the same: three in a row on a 3 by 3 grid.
Does this keep my score or ask me to sign in?
No account is needed. The score is only kept in the open page, so it resets when you close or reload it. Nothing about your games is sent anywhere.
Sources
- Tic-tac-toe, Wikipedia: alternative names, the convention that X plays first, solved game with a forced draw, 765 positions and 26,830 games up to symmetry, 91 / 44 / 3 end positions, the Newell and Simon strategy order and opening advice.
- Minimax, Wikipedia: the decision rule of minimising the possible loss in the worst case and its link to the Nash equilibrium in two-player zero-sum games.