Monte Carlo tree search
World models · 2006 · The classic algorithm under When search runs out
Monte Carlo tree search picks a move by playing many quick games from the current position and spending more of them on the moves that look best. This page builds it in four steps on a position small enough to check exactly.
World models · search
Monte Carlo Tree Search
How do you pick a move in a game far too big to search completely, when you don't even know how to score a position? Play many quick games from here, mostly at random, and keep count. Then spend more of those games on the moves that are doing well. That is Monte Carlo tree search, the method behind computer Go since 2006 and inside AlphaGo, AlphaZero and MuZero.
This page builds the algorithm in four steps on a real tic-tac-toe position, with the exact answer to check it against. When search runs out shows the neural-network version; this page is the classic one underneath it.
1 · The idea
Score a move by playing it out
Minimax (part 2) needs a score for every position at the bottom of its tree. For Go, nobody could write a good one by hand. The Monte Carlo trick replaces the score with experiments: from a position, play the game to the end with random moves, many times, and average the results. A position you tend to win from at random is probably a good one.
Random games alone are a weak judge. The second idea is the tree. Each experiment starts by walking down a growing tree of positions it has already seen, choosing moves that look strong or haven't been tried much. Only the end of each game is random. Over many games the tree grows deeper along the moves that matter, and those moves get played well, not randomly.
2 · Four steps, repeated
Select, expand, simulate, back up
This is UCT, “upper confidence bounds applied to trees” (2006), built on the UCB1 rule for multi-armed bandits. AlphaZero's PUCT, in part 2, swaps the logarithm for a neural network's prior.
Lab 1 · Step through a search
O to move. X holds two opposite corners, O the centre.O's six possible moves (root children)
Real MCTS, running in your browser: the whole tree is kept, though only the root's children are drawn. W/N is O's average result through that move (win 1, draw 0.5, loss 0). The exact answer comes from a full minimax search of the position: the four edges draw with best play, and both open corners lose, because X answers with a fork.
3 · Explore or exploit
Random games are fooled at first. The tree fixes it.
Watch the corners early on. A random X almost never finds the fork that punishes them, so random playouts make the corners look fine, sometimes best. As the tree grows, X's replies inside the tree stop being random: the search tries X's fork, sees it win, and from then on the corners' averages sink. That is the whole point of the “tree” in Monte Carlo tree search.
Lab 2 · How the estimates settle
O's average result for each move, over 3,000 games (log scale)Red lines are the two corner moves (lose with best play), teal lines the four edges (draw). Averages stay above the exact values because the bottom of every game is still random play; what matters for choosing is the ranking and the visit counts. Set c to 0 to see pure exploitation lock onto one move and stop learning about the rest.
4 · From random games to networks
Each step replaced a random part with a learned one
MCTS and UCT. The name and the averaging-to-minimax backup appear in a Go program that wins a computer-Go tournament the same year; UCT gives the selection rule above, with a guarantee that the choice converges to the best move given enough games.
AlphaGo. A policy network suggests which moves to try (the prior), and a value network judges positions. Leaf positions are scored by mixing the value network with a fast random-ish playout.
AlphaGo Zero and AlphaZero. The random playouts are gone: the value network alone scores each new position, and PUCT replaces UCT. Part 2's lab is this version.
MuZero. The game rules are gone too: the search runs inside a learned model of the game, which makes MCTS a way to plan with a world model.
Gumbel AlphaZero and MuZero. A different way to choose which root moves to try, which keeps improving the policy even with very few simulations per move.
5 · Where it struggles
What MCTS needs from a problem
A simulator
Every game played inside the search asks “what happens if I do this?”. Board games answer from their rules; anything else needs a world model, which brings model errors with it.
A short list of moves
The tree branches on every move. A car's steering or a robot arm has continuous controls; variants sample a handful of actions instead of listing them all, and sampling planners such as MPPI drop the tree entirely (the planner's path integral).
Time
More games give better answers, so the search is “anytime”: stop whenever you must. But a car re-planning ten times a second has very little time; see what world models still get wrong.
Hidden information (cards in poker) and chance (dice) need extensions: chance nodes that average over outcomes, or searching over guesses about the hidden state.