TL;DR
Monte Carlo tree search (MCTS) decides on a move by building a search tree one iteration at a time. Each iteration walks down the tree by a bandit rule, adds a new node, estimates that node's value by playing random moves to the end, and passes the result back up the path. After many iterations, the child of the root that was visited most is chosen.
Where you'll see it: in game programs such as Go engines and in AlphaZero-style systems, where a learned network guides the same loop, and in planning problems where the full tree is too large to enumerate.
Intuition
Suppose you are choosing a move in a game you cannot fully analyse. Exhaustive search of every line is impossible. A cheaper strategy is to play many quick games from each candidate move, count the wins, and favour the moves that win most often. That is the Monte Carlo part: random play gives a noisy estimate of how good a position is, namely how often it wins under random continuation.
The tree part makes this efficient. Random play from the root wastes effort on moves that are clearly bad. MCTS keeps a record of every position it has visited, and it uses that record to focus later simulations on promising lines. The focus comes from the multi-armed bandit idea of Multi-Armed Bandit: at each decision point, the algorithm balances the best-looking child against the children it knows least about.
The loop is shown below. The four phases repeat until the time or iteration budget runs out.
flowchart LR S[Selection: walk down by bandit rule] --> E[Expansion: add one new child] E --> R[Simulation: play random moves to the end] R --> B[Backpropagation: update counts and wins on the path] B --> S
The math
The search tree
Treat the game as a Markov Decision Process or as a two-player game. Each node stores a visit count and a total value , the sum of the outcomes from simulations that passed through . The mean value is . The outcome of a finished game is usually for a win and for a loss, or , , for win, draw and loss.
For a two-player game, the value stored at a node is usually from the point of view of the player who moved into that node. This keeps the backup simple: each node prefers the child that is good for the player to move there.
The four phases
- Selection. Start at the root. While the current node has been fully expanded (all its legal children exist in the tree), move to the child with the highest score, given by the rule in the next subsection.
- Expansion. At a node with an unexplored legal move, add one child for that move.
- Simulation. From the new node, play moves to the end of the game. The simplest policy chooses moves uniformly at random. A learned policy or value network can replace the random play, but the phase is the same: produce an outcome.
- Backpropagation. Walk back from the new node to the root. At each node on the path, increase by one and add the outcome to , taking the perspective of the player who moved into that node.
After the iterations, the move is chosen by the most-visited child of the root. Visit counts are preferred to mean values because they are more robust to a child that won only by luck on very few simulations.
The selection rule: UCT
The selection rule is UCB1 from Multi-Armed Bandit applied to each node's children. Let be a node with parent visit count and let be an exploration constant. The UCT score of child is
The first term exploits children with good records. The second explores children that have few visits relative to their parent. For outcomes in , the standard choice is , which is the same constant as in the bandit bound. In practice is tuned for the game and the value scale.
Kocsis and Szepesvári showed that applying UCB1 at every node makes the estimated value at the root converge to the true minimax value as the number of simulations grows. This consistency result is the theoretical reason the rule works, though it says nothing about how many simulations a given game needs.
Worked examples
The root has two children, A and B. After iterations total, A has been visited times with total value , and B has been visited time with value . Use .
- .
- For A: mean . Exploration term . Score .
- For B: mean . Exploration term . Score .
- B has the higher score, so selection goes to B.
B has a perfect record but only one visit, so its exploration term is large. Selection tries it again before committing to A, which is the bandit trade-off in one step. If B's single simulation had been a loss, its mean would be and its score would be , still above A's . Exploration is strong in the early iterations and fades as visits accumulate.
After 100 iterations at the root, three children have these counts and total values:
| Child | Visits | Wins | Mean |
|---|---|---|---|
| A | 60 | 36 | 0.60 |
| B | 30 | 21 | 0.70 |
| C | 10 | 6 | 0.60 |
- The most-visited child is A, with 60 visits.
- The child with the highest mean is B, at 0.70.
- MCTS normally plays A. The mean of B is higher but based on 30 simulations, against 60 for A.
- The visit count reflects where the search spent its effort, and the search spends more effort on moves whose bandit score stays high. A move that keeps being explored and still looks good is usually a more reliable choice than one with a high mean from fewer samples.
If the budget were doubled and B's mean held at 0.70 with its visits growing faster, B would overtake A in visits, and the two criteria would agree.
Tradeoffs and failure modes
| Situation | Problem | Better choice |
|---|---|---|
| Branching factor is very large | Expansion is slow and simulations rarely reach the same positions twice | Progressive widening, or a learned policy prior to rank children |
| Rollouts are random and the game is long | Random playouts are noisy and rarely informative | Replace rollouts with a learned value estimate |
| Game is deterministic and small | Full minimax with pruning is exact and cheap | Alpha-beta search, see Minimax Game |
| Time limit is tight | Too few iterations leave the tree shallow | Tune and the simulation policy; reuse the tree between moves |
| Opponent behaviour is known and exploitable | Uniform random rollouts assume a random opponent | Use a stronger rollout policy or a learned model |
| Values are not in | The constant assumes that scale | Normalise outcomes or retune |
The main failure is over-trusting random rollouts in games where the outcome depends on a few critical moves. A rollout can miss a tactic that a shallow search would find, and the tree then reinforces the wrong move. Strong systems combine MCTS with a value estimate so that simulations stop early and the estimate carries the rest.
History
The bandit-based selection rule for trees was introduced by Levente Kocsis and Csaba Szepesvári in 2006 as UCT (upper confidence bounds applied to trees). Around the same time, Rémi Coulom developed a tree-search Go program that used random playouts with a selective tree, and he coined the name "Monte Carlo tree search". Go programs such as MoGo and Crazy Stone then improved strongly on earlier methods, and MCTS became the standard approach for Go and for many other games where the branching factor was too large for classical search.
Later systems combined MCTS with deep neural networks. The AlphaGo line and AlphaZero used a learned policy to guide selection and a learned value in place of most random playouts, and MuZero extended the approach to learned models. The core loop of selection, expansion, evaluation and backup survives in all of them.
Check yourself
QuestionIn worked example 1, if B's visit count were 4 with value 3 and A stayed the same, which child would selection pick and why?Show answer
The root now has visits, so both exploration terms use . For B: mean , exploration term , score . For A: mean , exploration term , score . A is chosen. Its lower mean is outweighed by its exploration term, which is larger because it has fewer visits relative to the parent. Both terms must be recomputed from current counts at every selection.
QuestionWhy does MCTS back up the outcome to every node on the path, not only to the leaf?Show answer
The value of a leaf is an estimate for that position alone. Backing it up to every ancestor means each node's mean reflects all the simulations that passed through it, which is how the parent's choice among its children gets information. Without backup, the root would have no record of which first moves led to good outcomes, and selection could not use the bandit rule at the upper levels.
QuestionA researcher says that choosing the child with the highest mean value is always better than choosing the most-visited child. Assess this.Show answer
Not always. The mean is noisy when a child has few visits. A child that won the first two simulations has mean 1.0 but almost no evidence. Visit count is a proxy for how much the search trusted that child: the bandit rule keeps visiting a child whose score stays high, so a heavily visited child has survived many comparisons. Some implementations use a combination, such as the most-visited child with a minimum mean, to avoid both failure modes.
QuestionIn a two-player game, why are values stored from the perspective of the player who moved into a node?Show answer
At a node where player X has just moved, the parent node's decision is made by the other player, who wants the children that are good for them. Storing the value from the mover's point of view lets each node pick the child with the highest value for the player choosing among its children, and the sign is consistent through the tree. Storing from a fixed player's view would require flipping signs at alternating levels, which is easy to get wrong.