Tic-Tac-Toe
Play against an unbeatable computer or a friend — with the reason a perfectly played game can only ever end in a draw.
Your turn (X)
Take the corner, not the centre
Everyone is taught to open in the middle. It is the wrong advice, and the board is small enough to prove it rather than argue about it. Every opening draws against perfect defence, so the question that actually decides games is how much room your opponent has to go wrong. Solving all eight replies to each opening exactly:
| You open in… | Replies that lose | Replies that draw | What saves them |
|---|---|---|---|
| the corner | 7 of 8 | 1 of 8 | the centre |
| the centre | 4 of 8 | 4 of 8 | any corner |
| the edge | 4 of 8 | 4 of 8 | a corner, the centre or an edge |
Open in a corner and there is exactly one square that holds the draw — the centre. Miss it and you have lost. Open in the centre and your opponent has four saving replies, and they are the four corners, which are the most obvious squares on the board to reach for.
So the famous move is the forgiving one. Against a perfect opponent none of this matters and every game is drawn. Against a person, the corner is the difference between an even game and a seven-in-eight chance they hand it to you on the very first reply.
Why going first feels stronger than it is
The whole game fits in memory, so every line can be counted rather than estimated. There are 255,168 distinct games playable to the end, passing through 5,478 positions between them:
| Result | Games | Share |
|---|---|---|
| X wins | 131,184 | 51.4% |
| O wins | 77,904 | 30.5% |
| Drawn | 46,080 | 18.1% |
X wins 1.68 games for every one O wins, and only 18% of all possible games are drawn. That is where the sense that the first player is winning comes from — and it is misleading, because it counts every game equally, including the terrible ones. Restrict both sides to their best moves and all of it collapses to a draw. The advantage of going first is real, but it is entirely an advantage in how easy it is to play well, not in the outcome.
How to use
- Choose the computer or two-player mode.
- Take turns placing your mark.
- Get three in a row to win.
- Try to beat the perfect opponent — you cannot.
Frequently asked questions
Can the computer be beaten?
No. Tic-tac-toe is a solved game, and perfect play from both sides always draws. The computer here plays perfectly, so the best available result is a draw — which is the honest answer rather than a difficulty setting in disguise.
What is the best opening move?
A corner, which creates the most opportunities to fork later and gives an imperfect opponent the most ways to go wrong. The centre is the strongest single square, but a corner opening sets more traps against anyone not playing perfectly.
What is a fork?
Creating two lines of two at once, so your opponent can only block one. It is the only way to win against a competent player, since a single threat is always simply blocked. Recognising and preventing forks is essentially the whole of the game.
How many possible games are there?
255,168 distinct games if you count every sequence, though far fewer meaningfully different positions once symmetry is accounted for. It is small enough to have been solved completely by hand long before computers, which is why it is the standard first example in teaching game search.
Why is it a good programming exercise?
Because the whole game tree fits comfortably in memory, so the minimax algorithm can be implemented and understood in full without any of the approximations that larger games require. It teaches the idea cleanly before the practical complications arrive.
How old is the game?
Very. Three-in-a-row games were played in ancient Egypt and Rome, where a version called terni lapilli used three pieces per player that were moved rather than added. The paper-and-pencil form we know is comparatively recent, and the name tic-tac-toe is nineteenth century.
🔒 This tool runs entirely in your browser. Nothing you enter is uploaded, logged, or stored.