Tic-Tac-Toe AI

Analogous to Intelligence (or: how to think about AI)

There’s a lot of breathless hyperbole around AI these days, and honestly, many of those concerns are legitimate. Fears that AI (and technology in general) may depress wages, eliminate jobs, and degrade working conditions for average people are valid, and they’re not new. The Luddites said the same thing about power looms in 1811, and they weren’t wrong. Skilled textile workers watched machines that took decades to master get replaced by automated frames that any unskilled worker could tend. Sound familiar? The technology won, but the transition was brutal, and the people who bore the cost were rarely the ones who owned the machines. Don’t lose sight of that.

But what keeps surprising me is how different people’s expectations are from what AI can actually do.

I’ve been wrestling with how to explain to people who aren’t in tech what an AI is. Here’s what I came up with: think of it as a box. Literally. An AI is a box full of data and tools (programs and algorithms). AI Agents take it a step further, adding inputs like sensors and data feeds, and outputs like screens and API drivers. But that’s it. It’s a box.

Think about your own work for a minute. There are probably plenty of repetitive tasks that rely on a known set of data and a known set of rules. Those tasks are great for AI, and in those cases we should embrace its use. But if what you need is real discovery, creativity, or innovation to solve problems that don’t have answers yet, AI probably isn’t your answer. It can’t dream, it can’t innovate. AI literally can’t “think outside the box”… yet.

To put this “it’s just a box” idea to the test, I built the simplest AI I could think of: one that plays Tic-Tac-Toe. In our Tic-Tac-Toe box, we store the rules and the current board state (data), then use tools that compute every possible future game state, evaluating each branch of the game tree to find the best move on every turn. It’s a box. And it plays Tic-Tac-Toe perfectly.

Now some of you may balk at the simplicity of this description and example. But the box idea scales. A modern LLM may be trained on data scraped (hopefully legally) from the entire Internet, meaning it needs a very big box, but it’s still a box. The tools may be mind-numbingly complex (neural networks, RLHF, XGBoost, SVMs, Hidden Markov Models), but they’re still just tools in the box. For most people, the real question with AI is where it can be used today to make work more efficient. Think of this as a starting point, not a ceiling.

A solved game played against an unbeatable AI — watch the algorithm evaluate every possible future before it moves.
The colored numbers on the board and in the game tree are the minimax values the algorithm backs up through the game tree to choose its move. Square numbers (1–9) link each board cell to its node in the tree.

Tree appears when AI thinks
Pick a square to start  ·  Adjust settings below  ·  You can force the AI to move by clicking a circle in the tree
Your turn
Positions evaluated: 0
AI MOVES IN
--
First player
Your mark
Move delay 10000 ms
Show reasoning
Score overlay & tree — from the AI’s perspective
Green — AI’s best move
Yellow (=) — draw — “=” avoids confusion with the mark O
Red — human wins that line
Scores: +(10−depth) AI win  ·  −(10−depth) human win  ·  = draw
A +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.

How minimax backs scores up the tree

Near the end of a game with two empty squares, the AI tries both options. Terminal scores (wins or losses) are computed at the leaves and bubble back up to the root so the AI can pick the best guaranteed outcome.

CURRENT POSITION — AI to move, squares 5 and 6 are empty sq 5 sq 6 AI plays sq 5 AI plays sq 6 +9 O wins · +(10−1) = +9 −8 backed up ↑ Human's turn — only sq 5 left Human plays sq 5 −8 X wins via middle column · −(10−2) = −8 DEPTH 1 DEPTH 2 AI maximizes: picks max(+9, −8) = +9 → plays sq 5 and wins
View minimax source code (the exact functions running this game)
Loading…