How the AI Opponent Thinks: Minimax and the Game Tree
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.
- It never hopes. It assumes you'll always find your best reply, so it only chooses lines that hold up against perfect defence.
- It plays for the guarantee. On 3×3 it can see all the way to the end, so it can never lose — the best you can force is a draw.
💡 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.
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.
- Grab the centre early on big boards, before the AI's limited search horizon can react to it.
- Build open-ended threats several moves deep — beyond the depth the AI can fully calculate.
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.