← Tic-tac-toe against the computer

Tic-Tac-Toe Strategy: How to Never Lose, and How to Win

Every claim on this page was checked by a program that plays out every possible game. Where it says a move loses, it loses against correct play.
The short answer

Tic-tac-toe is solved: with perfect play on both sides it is always a draw, so nobody can force a win against an opponent who makes no mistakes. You never lose if you win when you can, block when you must, and stop your opponent's forks. You win when the other side slips — and the corner opening gives them the most room to slip: seven of their eight replies lose, and only the centre holds.

Why the centre and the corners matter

There are eight lines on the board: three rows, three columns and two diagonals. A square is worth as much as the number of lines it belongs to. The centre is on four of them, each corner on three, each edge square on just two.

How many of the eight lines pass through each square.

That is the whole reason the centre and the corners are the squares to fight over, and why an edge is the weakest place to start. It is also why the two most important defensive answers below are “take the centre” and “take a corner”.

The fork: how games are actually won

A threat is two of your marks in a line with the third square empty. One threat wins nothing: the other side simply blocks it. A fork is a move that makes two threats at once. Only one can be blocked, so the second one wins.

Your last move (ringed) makes two threats: the left column and the bottom row. They can block only one square (✓).

Almost every game of tic-tac-toe that is not a draw is decided by a fork, and almost every loss starts one move earlier, with a move that allowed it. So the defence is not “block threats” — anyone sees those — but “do not let a fork appear”.

The move order that never loses

On every turn, take the first move on this list that is available. It is the order Allen Newell and Herbert Simon used for their tic-tac-toe program in 1972. We ran it against every possible sequence of the opponent's moves: it never loses, whether it moves first or second — with the precise wording of rule 4 below, which is where most retellings go wrong.

  1. Win. If you have two in a line and the third square is empty, complete it.
  2. Block. If the opponent has two in a line with the third square empty, take that square.
  3. Fork. If a move gives you two threats at once, play it.
  4. Block their fork. If the opponent has exactly one square that would give them a fork, take it. If they have two such squares, do not take either: make a threat of your own that forces them to block on a square that is not one of the two.
  5. Centre. Take it if it is free.
  6. Opposite corner. If the opponent holds a corner and the corner opposite it is free, take it.
  7. Any free corner.
  8. Any free edge.

The list guarantees a draw, not a win. It also does not always pick the trickiest move — for that, see the openings below.

Moving first: which opening gives the most chances

All nine first moves lead to a draw with perfect play. What differs is how many of the opponent's replies lose on the spot:

Your first moveReplies that loseReplies that hold
A corner7 of 8only the centre
The centre4 of 8any corner; every edge loses
An edge4 of 8the centre, the two neighbouring corners, the opposite edge

So the corner is the strongest practical opening: the opponent has exactly one good answer. If they find it, play the opposite corner. That sets the trap below — and against a player who knows the trap, it is still a draw.

Corner, centre, opposite corner. Their move now: any corner loses (✗), any edge holds (✓).
They took a corner. It threatens the diagonal, so you block in the last corner (ringed) — and that block is a fork.

If they answer your corner with anything except the centre, a fork is never more than two moves away. A typical line: they reply on an edge next to your corner; you take the centre, which threatens the diagonal; they block in the far corner; you take the remaining corner on your side and have two threats.

Corner, they take an edge; centre, they block in the far corner; the last corner on your side is a fork.

Opening in the centre works the same way one step later. If they reply in a corner (the correct answer), take the opposite corner: now every edge loses for them and only a corner holds.

Centre, corner, opposite corner. An edge loses for them (✗), a corner holds (✓).

Moving second: the replies that hold

The second player cannot win against correct play, but has only one real job: answer the first move correctly, then avoid the two classic traps.

They open in a corner: only the centre holds.
They open in the centre: any corner holds, every edge loses.
They open on an edge: the centre, the two neighbouring corners or the opposite edge.

Trap one: two opposite corners around your centre. They open in a corner, you take the centre, they take the opposite corner. The natural-looking move — another corner — loses: you threaten, they block, and their block is a fork. Take an edge instead: it makes a threat on a square that does them no good.

Their two corners, your centre. An edge holds (✓), a corner loses (✗).

Trap two: their centre, your corner, their opposite corner. Here it is the other way round: you must take a corner, and an edge loses.

Their centre and the corner opposite yours. A corner holds (✓), an edge loses (✗).

How to beat each level on this site

The numbers in this section were computed from the game's own code: every line of play, against every choice the computer can make, including its random ones.

Normal takes a win when it sees one and otherwise plays anywhere. It never blocks. Put two in a line and complete them on your next move. With the best play you win 99.5% of games when you move first and about 92% when it does; the rest is a random move that happens to land on your square, or a line you left open for it.

Hard wins when it can, blocks your threats, and otherwise takes the centre, then a random corner. When you move first, it is a forced win, every time: open in a corner — Hard takes the centre; take the opposite corner — Hard has no threat to block, so it takes one of the two free corners, which makes a threat; block it, and your block is a fork. When Hard moves first it always opens in the centre, and from there no sequence of your moves beats it, not even with luck: take a corner and the game is a draw.

Expert plays perfectly and cannot be beaten; a draw is the best result there is. Among equally good moves it picks the one that leaves you the most losing replies. In practice: moving first, it always opens in a corner, where seven of your eight replies lose — answer in the centre. Its next move is next to its own corner, an edge or a corner, and it makes a threat: block it, then keep following the move order above. When you move first, it answers a corner with the centre, the centre with a corner, and an edge with a corner next to it.

The mistakes that actually lose games

  • Answering a corner with anything but the centre. It is the most common losing reply there is, because seven of the eight replies are wrong.
  • Taking a corner when the opponent holds two opposite corners around your centre. An edge is the only safe move there.
  • Making your own threat when the opponent already has one. A block comes first, every time, unless you can win on the spot.
  • Blocking the obvious threat and missing the fork behind it. Before each move, ask which square would give the opponent two threats.
  • Starting on an edge. It does not lose, but it controls only two lines, and half of the opponent's replies hold — as many as after the centre, from a weaker square.

The game in numbers

  • 255,168 different games can be played to the end. The first player wins 131,184 of them, the second 77,904, and 46,080 are draws.
  • If both sides play completely at random, the first player wins 58.5% of games, the second 28.8%, and 12.7% are draws. The first move is a real advantage — just not a decisive one.
  • 765 essentially different positions exist once rotations and reflections are set aside — small enough to search on paper, which is why the game is the classic first exercise in game-playing programs.
  • 8 lines decide everything: 4 pass through the centre, 3 through each corner, 2 through each edge.

Tic-tac-toe is the smallest game in our list of solved games. How a machine searches it, square by square, is the first step of how machines learned to play; if the game has become too easy, its big sister ultimate tic-tac-toe puts nine boards in one and is nowhere near solved by hand.

Questions and answers

Is tic-tac-toe a solved game?

Yes. With perfect play on both sides it always ends in a draw. The game is small enough — 255,168 possible games, 765 essentially different positions — for a short program to check every line.

Can you always win at tic-tac-toe?

No. Against an opponent who makes no mistakes the best result is a draw. You win only when the other side slips; the corner opening gives them the most chances to, because seven of their eight replies lose.

What is the best first move in tic-tac-toe?

A corner. Every first move draws with perfect play, but after a corner only one reply — the centre — avoids a loss. After the centre or an edge, four of the eight replies lose.

What should I play if my opponent starts in a corner?

The centre, and nothing else: every other reply loses against correct play. If they then take the opposite corner, take an edge, not a corner.

How do you never lose at tic-tac-toe?

On every move: win if you can, block if you must, make a fork if you can, stop the opponent's fork, then prefer the centre, the corner opposite theirs, any corner, and only then an edge. Checked against every possible game, this order never loses.

What is a fork in tic-tac-toe?

A move that creates two threats at once — two lines that each need one more mark. The opponent can block only one, so the other wins. Nearly every decisive game ends with a fork.

Can you beat the computer at tic-tac-toe?

Not a perfect one: the best you can get is a draw, and that is what the Expert level on this site plays. Weaker programs can be beaten. Here, Normal never blocks, and Hard loses every time to corner, then opposite corner, when you move first.

Does the first player have an advantage?

Yes, but not a winning one. With random play the first player wins 58.5% of games and the second 28.8%. With perfect play the advantage disappears and the result is a draw.

Play tic-tac-toe against the computer →
Where to go from here
To cite this page: “Tic-Tac-Toe Strategy: How to Never Lose, and How to Win”, You vs Computer, https://youvscomputer.com/games/tic-tac-toe-strategy.html