Inside the AI

How the AI Opponent Thinks: Minimax and the Game Tree

By LK Forge  ·  4 min read

When you pick Hard in our game, you're not playing against random moves — you're playing against a tiny search engine that imagines the future. Here's the surprisingly simple idea behind it, and why it gets beatable as the board grows.

The Game Tree

Every position branches into the moves you could make next; each of those branches into the opponent's replies, and so on until the game ends. Drawn out, that's a game tree — a fan of every possible future. The leaves are final positions, each one a win, loss, or draw. The AI's whole job is to figure out which branch leads to the best guaranteed leaf.

Minimax: Assume the Opponent Plays Perfectly

The AI scores leaves simply: +1 for an AI win, −1 for your win, 0 for a draw. Then it works backwards up the tree with one rule — on its turn it picks the move with the highest score (maximising), and it assumes that on your turn you'll pick the move that's worst for it (minimising). That alternation of max and min is the whole algorithm: minimax.

💡 Why Hard never blunders on 3×3: the entire 3×3 tree is small enough to search completely. The AI already knows the outcome of every move before you've finished your turn.

Alpha-Beta Pruning: Searching Less, Seeing the Same

Searching every branch is wasteful. Once the AI finds a reply that already refutes a move, it doesn't need to examine that move's other branches — they can't change the decision. Skipping them is called alpha-beta pruning, and it can cut the work dramatically without changing the answer. Same perfect play, a fraction of the effort.

Completed 3x3 tic-tac-toe board against the Hard AI, every line blocked, ending in a draw
A full game against Hard — full-depth minimax — played out to a draw, no three in a row for either side. On a 3×3 board that is the best case: perfect play forces the tie.

Why Bigger Boards Make It Beatable

The catch is size. A 3×3 board has at most nine moves; a 10×10 board has a hundred, and the tree grows astronomically — far too large to search to the end in a browser. So on larger boards the AI searches to a limited depth and estimates the rest with a heuristic instead of solving it exactly. That gap is your opening.

Minimax is the same principle behind the game theory of Tic-Tac-Toe. For hands-on tactics, see our strategy guide — then test them against Hard in the game.

BEAT THE AI