Monte Carlo tree search
How a program chooses a move by playing random games and keeping score in a tree. One full round of selection, expansion, simulation and backpropagation, with every number worked out.
In 30 seconds
Monte Carlo tree search decides what to do next by trying things out. It builds a tree of positions and, for each one, records how many of the random games played through it were won.
Every round has four phases: select a promising path, expand it by one new position, simulate a random game from there, and pass the result back up.
A score called UCB balances moves that have done well against moves barely tried. Because positions are judged by playing them out, no hand-written scoring formula is needed, which is what made the method work for Go.
Monte Carlo tree search, step by step
For simplicity every node counts wins for the player choosing at the root. Real programs count each node’s wins for the player who moved into it, so the opponent’s replies are selected by what is good for the opponent.
- Step 1: A tree that keeps score. Monte Carlo tree search (MCTS) chooses a move by playing many random games and keeping score in a tree. Each node is a position, labelled with how many of the games played through it were won. So far 12 games have been tried from the current position: 8 began with move A, and 6 of those were won.
- Step 2: Phase 1: selection. Each round starts at the root and picks the move with the highest UCB (upper confidence bound) score: its win rate plus a bonus that is large for moves tried rarely. A has the best win rate, but B has been tried only twice and its bonus tips the balance. This weighs exploiting what looks good against exploring the unknown.
- Step 3: Phase 2: expansion. The walk down the tree stops at a node that still has a move nobody has tried. One new child is added for that move: a position the search has never visited. It starts with no games and no wins.
- Step 4: Phase 3: simulation. From the new position the game is played out to the end with random moves. Only the rules and the final result are needed. No formula for judging a half-finished position is needed, which is why the method suits games like Go, where a good one is very hard to write. This playout ends in a win.
- Step 5: Phase 4: backpropagation. The result travels back up the path. Every node on it counts one more game and, because this one was won, one more win. The new node reads 1/1, B rises from 1/2 to 2/3, and the root from 7/12 to 8/13. The next round will select using these updated numbers.
- Step 6: Repeat, then choose. The four phases repeat thousands of times, for as long as the clock allows. Promising moves keep being selected, so the tree grows deep under them and stays shallow elsewhere. When time is up, the move with the most visits is played. The counts here are an example of how they might look after 1,000 rounds.
- Step 7: Inside AlphaGo. AlphaGo, which beat Go champion Lee Sedol 4 games to 1 in 2016, is this search guided by two neural networks. A policy network suggests which moves deserve attention, and a value network estimates who is ahead at a new position, used alongside fast playouts. Its successor AlphaGo Zero dropped random playouts altogether.
Try it yourself
Learn this first
Learn next
- Reinforcement learningAn agent on a small grid learns by trial and error which moves earn the most reward. Beginner
- Neural networksFollow numbers through one tiny network by hand, and see why the bend matters. Beginner
- Q-learningLearning the value of each move by trial, error and one update rule. Advanced
Spotted a mistake on this page?