How I Solved Tic-Tac-Toe at 9 and Never Lost Again

February 26, 2026

How I Solved Tic-Tac-Toe at 9 and Never Lost Again

A bored kid, a notebook, and 255,168 possible games. How mapping every tic-tac-toe position by hand taught me game theory before I knew what game theory was.

algorithmspersonal

The summer I got serious

I was 9. My older cousin beat me at tic-tac-toe five times in a row, each time in a different way. I didn't understand how — the board was nine squares. I could see the whole game. How was I losing?

I didn't ask him to teach me. I went home and got a notebook.

The goal was simple: I was going to map out every possible game. If I could see every position the board could ever be in, no move would ever surprise me again. My cousin would never win again. Nobody would.

That notebook became an obsession.

The first insight: the game is finite

Tic-tac-toe has exactly 255,168 possible games from start to finish. If you account for symmetry and rotations, that collapses to around 26,830 unique positions. I didn't know those numbers at 9. But I understood the core idea intuitively: the game is finite. There are only so many moves. Every possible board state can be listed.

The plan: draw them all.

I didn't actually get through 255,168 — I started finding patterns way too fast. After maybe 50 games mapped out on paper, the structure was obvious. The game wasn't random. It had a shape.

Not all squares are equal

The first thing I noticed: where you play first completely determines what's possible later. I mapped three types of openings — center, corner, edge — and the difference was stark.

opening move comparison

X
center↑ strongest
X
corner↑ good
X
edge↑ risky

The center square touches every row, column, and both diagonals — four lines total. An edge square participates in only three. The difference doesn't sound like much until you're three moves in and realize you have nowhere to build from.

After enough games, I stopped opening anywhere except center or a corner. The losses dropped immediately. My cousin started getting annoyed.

The corner opening: a near-forced win hiding in plain sight

My actual go-to strategy wasn't to open center. I always opened with a corner.

Here's why: if your opponent plays anything other than center in response, they have already lost. Not "they're at a disadvantage." Lost. Every non-center response to a corner opening is a guaranteed loss against optimal play. That's 7 out of 8 remaining squares that seal their fate on move 2.

Most people don't take the center. They look at the corner you just played, they think "I should play near the middle," and they pick an edge — one of those four squares bordering the center. It feels like a reasonable positional move. It isn't. Edge responses to a corner opening are the worst possible reply.

So if your opponent grabs center (the only move that doesn't immediately lose), the cheeky response is the opposite corner. Play the corner diagonally across from yours. This looks strange — why go to the far corner instead of building toward the middle? — and that confusion is exactly the point.

Now your opponent has 6 remaining squares to choose from. 4 of them are edges. And people, by instinct, pick edges. They always pick edges. They feel "safe" and "central." They're not. Every edge response at this point creates an immediate fork for you — two ways to win, one block available.

The 2 remaining corners also lose, just with slightly more steps. The board is effectively solved the moment they respond to your opposite corner with anything.

The math: after corner → center → opposite corner, all 6 of your opponent's remaining moves lose. The game is over. They just don't know it yet.

The fork: the move that can't be stopped

The real discovery was the fork.

A fork is when you create two threats simultaneously. Your opponent can only block one. You win the other. It's not a clever bluff — it's a forced win. Engineered from the opening.

fork trap

1 / 7
X

X opens with top-left corner. Flexible — keeps multiple winning paths open.

Once I understood forks, the game changed entirely. I stopped playing reactively and started playing for specific board positions. Every opening move was chosen to make a fork possible by move 5.

Opponents would feel fine — blocking my threats, making their plays — and then suddenly there'd be two ways to lose and only one block available. The look on their face was always the same.

The notebook was getting full. Lines, circles, arrows, crossed-out dead ends. My mom asked if I was doing homework.

I said yes.

Three rules that cover everything

After a few weeks of obsessive mapping, the entire game compressed into three rules:

  1. Take center if it's free. It maximizes your future options and limits theirs.
  2. Take corners over edges. Corners enable forks. Edges almost never do.
  3. Spot forks early — yours and theirs. If you can create one, do it. If they're building one, stop it immediately, even if it means ignoring an obvious threat.

Rule 3 is the one people miss. Most players focus on their own line and don't notice their opponent setting up a position two moves ahead. Once you train yourself to see forks coming, you can disrupt them before they materialize.

These three rules don't guarantee a win — with perfect play from both sides, tic-tac-toe always ends in a draw. But they guarantee you'll never lose.

This is minimax

I didn't know it at the time, but what I'd done by hand was a simplified version of the minimax algorithm — the foundational algorithm behind chess engines, Go programs, and most two-player game AI.

Minimax works like this: from any board position, imagine every possible move. For each move, imagine every opponent response. For each response, imagine every reply. Keep going until the game ends. Score each terminal state: +10 if you win, -10 if you lose, 0 for a draw. Then work backwards — at each step, assume your opponent picks the move that minimizes your score, and you pick the move that maximizes it.

Applied to tic-tac-toe, minimax proves something that felt true to my 9-year-old self: with optimal play, tic-tac-toe always ends in a draw. You can only win by exploiting your opponent's mistakes. You cannot force a win against a perfect opponent.

Which meant the actual goal was simpler than I thought: never make a mistake, and wait.

Try to beat it

The implementation below plays a perfect minimax game — every move is provably optimal. Against perfect play, the best you can do is draw.

You play as X.

play vs algorithm
0W/0D/0L
your move (X)

I accumulated a lot of wins at 9. I told people I was just "good at tic-tac-toe." But that wasn't it. I had solved the game. There's a difference between being good at something and having removed the possibility of losing from it entirely.

That asymmetry stayed with me. A lot of what looks like skill is really just preparation that other people didn't bother with. Sometimes the game is already decided before the first move.