+(10−depth) AI win · −(10−depth) human win · = drawA +7 means the AI sees a forced win 3 moves away (10−7=3). A −5 means you can force a win in 5 moves.
What you’re watching
Tic-Tac-Toe is a solved game — one where every possible situation has been analyzed, so a “perfect” player can always make the best move. The minimax algorithm is the decision-making tool that finds that best move. For a game like Tic-Tac-Toe, minimax works by building a tree of every possible future and choosing the branch with the best guaranteed outcome.
Reading the scores
Scores use +(10−depth) for an AI win and
−(10−depth) for a human win, so depth is
baked into the number:
- +9 — AI wins in 1 half-move (10−9=1)
- +7 — AI wins in 3 half-moves (10−7=3)
- = — draw with perfect play
- −4 — you win in 6 half-moves (10−6=4)
- −5 — you win in 5 half-moves (10−5=5)
- −8 — you win in 2 half-moves (10−2=8) — very soon
This forces the AI to take the fastest win and accept the slowest loss — it never stalls when it’s ahead.
When all scores are negative, the AI is already in a losing position. It picks the least negative score — the one furthest from 0 — to delay the loss as long as possible. −6 beats −8 because the loss is 4 half-moves away instead of 2.
How the tree works
The AI imagines every move it could make (Depth 1), then every reply you could make (Depth 2), then every counter-reply, all the way to a terminal state. At Depth 1 it maximizes (picks green). At Depth 2 it minimizes — it assumes you’ll pick the move most damaging to it. Those scores bubble back up: each node inherits the best or worst of its children.
Square numbers (1–9) on each node match the corner labels on the board so you can trace any branch to its cell instantly.
When all moves look equal
You may notice the AI sometimes makes a move that seems passive — ignoring a square that “puts more pressure” on you. This happens when multiple moves all score = (draw). To basic minimax they are identical: the algorithm picks the first one in the list.
In reality, some draws require near-perfect defense from you while others are easy to hold. Distinguishing between them requires a secondary evaluation heuristic — something beyond pure minimax. This is one of the key limitations the algorithm exposes.