Let's set expectations honestly: our Tic-Tac-Toe AI runs the Minimax algorithm, which examines every possible future of the game before each move. Tic-Tac-Toe is small enough to be completely solved — there are only 255,168 possible games — so a perfect player literally cannot blunder. Against it, victory is mathematically off the table. The best achievable result is a draw, every single time.
So why learn strategy? Three reasons. First, drawing a perfect machine consistently is itself the mastery test — one imprecise move and the AI executes you instantly. Second, the strategies that merely draw against perfection win constantly against humans, who err all the time. Third, it's the cleanest little lesson in game theory you'll ever get for free.
The geometry: why some squares are better
Count the winning lines through each square. The centre touches four (one row, one column, two diagonals). Each corner touches three. Each edge touches only two. That one observation generates nearly all correct play: centre and corners are premium real estate; edges are where mistakes live.
The fork: the only way anyone ever wins
Between players who can see one move ahead, a single threat never wins — it just gets blocked. Games are won by the fork: a move that creates two winning threats simultaneously. Your opponent blocks one; you complete the other.
The classic setup, playing X: open with a corner. If your opponent answers anywhere but the centre, take another corner sharing a line with your first that passes through an empty square — you now threaten along two lines at once, and no single reply stops both. This "double corner" trap wins more casual games than every other pattern combined.
Opening theory in three sentences
- Moving first? Corner is the trickiest choice against humans (it maximises their chances to go wrong — only a centre reply is safe). Centre is the simplest strong choice. Never open on an edge.
- They opened corner? You must take the centre. Any other reply loses to perfect play — an edge response lets the fork machinery start, and the game is decided before the board is half full.
- They opened centre? Take a corner. Then block threats and mirror their play; accurate defence holds the draw comfortably.
The complete priority list (never lose again)
This decision procedure — famously distilled by early AI researchers studying how people learn the game — plays perfectly. At every turn, take the first rule that applies:
- Win: if you have two in a line, complete it.
- Block: if they have two in a line, block it.
- Fork: create a double threat if you can.
- Block their fork: if they could fork next turn, either block the fork square or — better — make a threat elsewhere that forces them to respond instead of forking. (Watch the two-opposite-corners trap: if they hold opposite corners and you hold centre, reply with an edge, not a corner.)
- Centre, if free.
- Opposite corner: if they occupy a corner, take the one diagonally opposite.
- Any empty corner.
- Any empty edge.
Follow that list without deviation and you will never lose a game of Tic-Tac-Toe again — against our AI, your smug cousin, anyone. Our streak counter exists precisely for this: survive draw after draw against perfection and watch the number climb.
Winning against humans (legally)
Humans aren't Minimax. They miss diagonal threats, they answer corners with edges, and they crumble under tempo. Ethical exploitation: play your moves briskly to deny thinking time, prefer corner openings to maximise their chances to go wrong, and set forks on the side of the board where they aren't looking — people fixate on the region of the last move. None of this works on the machine; all of it works at kitchen tables.
Why a "pointless" game is worth mastering
Tic-Tac-Toe is the gateway drug of game theory. It teaches, in miniature, the concepts that scale up to chess and Go: looking ahead, forcing moves, double threats, and the idea that some games have a knowable objective truth. It's also the perfect first strategy game to teach a child — the priority list above is a genuine little algorithm, and watching a kid discover the fork on their own is watching structured thinking switch on. Not bad for a grid you can draw in the sand.
Test the priority list
Our Minimax AI never blunders. Bring the algorithm above and see how long you can hold the draw streak.