Monte Carlo Tree Search
Monte Carlo Tree Search is a rollout algorithm with memory: it accumulates value estimates across simulations and steers later ones toward promising branches. We work through the four steps — selection, expansion, simulation, backup — the UCT selection rule computed on real numbers, the asymmetric growing tree, and the full pseudocode.
╌╌╌╌
This builds on Decision-Time Planning, which developed real-time DP, heuristic search, and rollout algorithms — planners that compute one action for the current state and discard the work. Rollouts throw away every simulated trajectory. Monte Carlo Tree Search keeps them, and that one change is what carried computer Go from weak amateur to superhuman.
Monte Carlo Tree Search
Monte Carlo Tree Search (MCTS) is a rollout algorithm with memory. Plain rollouts throw away every simulated trajectory; MCTS accumulates the value estimates from successive simulations and uses them to steer later simulations toward the higher-rewarding parts of the space.1 It is largely responsible for the improvement of computer Go from a weak amateur level in 2005 to grandmaster (6 dan or more) in 2015, and, combined with a deep neural network, it is the search behind the 2016 AlphaGo victories. It applies to any single-agent sequential problem with a model fast enough for repeated multistep simulation, not only games.
Like any rollout algorithm, MCTS runs after each new state to select the action, is an iterative process that simulates many trajectories from the current state to a terminal state (or until discounting makes further reward negligible), and repeats until a compute budget is spent. Its one addition is the tree. MCTS maintains a tree rooted at the current state, holding Monte Carlo value estimates for the state–action pairs most likely to be reached in a few steps. Any simulated trajectory passes through the tree and then exits it at some leaf. Inside the tree, where it has estimates for at least some actions, MCTS selects with an informed tree policy that balances exploration and exploitation — for example an -greedy or UCB rule. Outside the tree, and at the leaves, it falls back to the simple rollout policy (the default policy).
The four steps
Each iteration of a basic MCTS consists of four operations, repeated until time runs out.
- Selection. Starting at the root, a tree policy based on the action values attached to the tree's edges traverses the tree to select a leaf node.
- Expansion. On some iterations (depending on the application), the tree is expanded from the selected leaf by adding one or more child nodes reached from it via unexplored actions.
- Simulation. From the selected node — or one of its newly added children — a complete episode is simulated with actions chosen by the rollout policy. The result is a Monte Carlo trial: tree policy inside the tree, rollout policy beyond it.
- Backup. The return of the simulated episode is backed up to update (or to initialize) the action values on the tree edges the tree policy traversed this iteration. No values are saved for the states and actions the rollout policy visited beyond the tree.
The growing tree
Over many iterations the tree grows unevenly — deeper along branches that keep producing high returns, barely at all along branches that do not. This asymmetric growth is deliberate: MCTS spends its expansions where they matter.
UCT: the tree policy
The tree policy supplies MCTS's exploration–exploitation balance: at each node, prefer actions with good estimates so far, but add a bonus for actions that have barely been tried — a value estimated from two samples is far less reliable than one from two hundred. The most common rule that does this treats each node as a bandit and applies UCT (Upper Confidence bounds applied to Trees), which selects, among the actions available at state , the one maximizing an upper confidence bound:
Here is the current Monte Carlo estimate (exploitation), is the number of times has been visited, the number of times action was taken from , and tunes the exploration weight. The bonus is large for actions tried seldom relative to their parent, so it pulls selection toward under-explored actions; as grows, the bonus shrinks and the value term dominates.
Any action with is treated as having infinite bound and is selected first — every action gets tried at least once before the bound refines. This is the UCB1 bandit rule applied at each internal tree node.
A UCT selection, computed
Put real numbers on the bound. Suppose the root has been visited times and has three actions with the statistics below; take exploration weight (a common choice when returns are scaled to ).
| action | bonus | UCT score | ||
|---|---|---|---|---|
Here . The greedy choice by value alone is (highest ), but UCT selects : its low visit count gives it a large exploration bonus , enough to overtake the better-valued but well-explored and . This is the intended behavior: an action that might be good but has barely been tried is selected for further sampling.
Now suppose the simulation through returns a poor , dragging its mean to and its count to . Recompute with , :
while 's score rises only slightly to . So is still selected next — one bad rollout does not eliminate it — but each additional visit shrinks its bonus and sharpens its mean, and after a few more poor returns its score will fall below 's and selection will move on. The bound keeps sampling uncertain actions until accumulated evidence, not a single sample, settles their value.
The full algorithm
Putting the four steps and the UCT tree policy together gives the standard decision-time procedure. Each call plans from the current root state and returns the action to play; the environment then advances and the whole thing runs again.
- 1create root node for state
- 2while time budget remains do
- 3Selection: descend by the tree policy (UCT)
- 4while is fully expanded and non-terminal do
- 5child of maximizing
- 6if is non-terminal thenExpansion
- 7new child of from an untried action
- 8Simulation to a terminal state
- 9repeatBackup along the traversed edges
- 10
- 11running mean of returns
- 12parent of
- 13until is above the root
- 14return action from with the largest visit count
After the budget is exhausted, the agent selects a root action by the accumulated statistics — commonly the action with the largest visit count (robust to outliers) rather than the largest value. The environment transitions to a new state, and MCTS runs again, usually starting from the surviving subtree rooted at the new state (any descendants of the chosen child are reused; the rest is discarded).
Why MCTS works
MCTS's success follows from principles already covered in this course. At its base it is a decision-time rollout algorithm on Monte Carlo control from the root, so it inherits online, incremental, sample-based value estimation and one-step policy improvement. Beyond that, it saves the action-value estimates on the tree edges and updates them with the sample updates of reinforcement learning. By incrementally expanding the tree along high-return trajectories, MCTS effectively grows a lookup table — a partial action-value function — with memory allocated to the state–action pairs in the initial segments of high-yielding sample trajectories. It gets the benefit of a learned concentrated where it matters, without approximating a value function globally, and it retains past experience to guide exploration.
From MCTS to AlphaZero
Finally, the leaf evaluation and the rollout policy need not stay simple. Plain MCTS evaluates a leaf by rolling out to termination under a weak default policy — noisy, and only as good as that policy. Replace the rollout with a deep neural network that maps a position to a value estimate and a policy prior , and fold that prior into the tree policy (a PUCT-style variant of UCT that biases selection toward high-prior actions), and the search becomes much stronger: the network supplies the leaf values and the move suggestions that make a deep, focused lookahead tractable, while MCTS supplies the lookahead that corrects the network's errors. Train that network by self-play, using the search's own visit counts and game outcomes as targets, and MCTS becomes the search inside AlphaGo and AlphaZero. The full account — the value/policy network, self-play training, and the tree-search integration — is the subject of the deep-RL case studies.
From UCT to AlphaZero and MuZero
The four-step MCTS above is the tabular skeleton; the systems that made it famous are a decade of additions, each traceable to a canonical paper.
UCT. The tree policy this lesson calls UCT is Kocsis and Szepesvári's Upper Confidence bounds applied to Trees, which analyzed MCTS as a nested set of bandit problems and proved that treating each node with the UCB1 rule makes the value estimate at the root converge to the minimax (optimal) value, with the probability of selecting a suboptimal root action going to zero.2 That guarantee is why UCT, rather than plain -greedy, became the default tree policy: it is the reason the asymmetric tree grows toward the right branches.
AlphaGo. Silver and colleagues combined MCTS with two deep networks — a policy network to narrow the search to plausible moves and a value network to evaluate leaf positions without a full rollout — and defeated a professional Go player, then the world champion, on a board long thought a decade away from computer mastery.3 The search is the MCTS of this lesson; the networks replace the weak default rollout policy and the hand-built leaf heuristic.
AlphaZero. The successor stripped out every Go-specific component — no human games, no handcrafted features, no separate rollout — and learned from self-play alone, using a single network for both value and policy and folding the policy prior into the tree policy (a PUCT variant of UCT that biases selection toward high-prior actions). One algorithm reached superhuman play in Go, chess, and shogi, each from the rules alone.4 The training target is the search's own visit-count distribution, so the network learns to imitate the improved policy the search produced — generalized policy improvement, with MCTS as the improvement operator.
MuZero. The last assumption to fall was the model itself. MuZero learns a latent dynamics model and runs the same MCTS over it, so it plans without ever being told the environment's rules — matching AlphaZero on board games and setting records on Atari, where the rules are not available in closed form.5 This is decision-time planning in a learned model: the search of this lesson, run inside a representation the agent learned.
In summary: to act well at a state, a global policy is not always needed. A good action for this state can be computed by looking ahead from it — with asynchronous value iteration on the states actually visited (RTDP), a lookahead tree backed up from leaf estimates (heuristic search), Monte Carlo estimates under a rollout policy (rollouts), or a tree grown asymmetrically toward promising continuations (MCTS). The deeper the lookahead, the less the imperfect value function matters — and with a learned network standing in for both the leaf value and the rollout, that lookahead is what carried reinforcement learning to superhuman play.
Footnotes
- Sutton & Barto, §8.11 — Monte Carlo Tree Search: MCTS as a rollout algorithm with memory, the four steps selection/expansion/simulation/backup (Figure 8.10), tree vs. rollout (default) policy, the UCB/UCT tree policy (Chapter 2), root action by visit count, and the extension to AlphaGo's network-guided search in §16.6. ↩
- Kocsis, L., & Szepesvári, C. (2006),
Bandit Based Monte-Carlo Planning,
ECML — UCT: applying the UCB1 bandit rule at each tree node, with a convergence proof that the root value estimate approaches the optimal (minimax) value and the probability of a suboptimal root action tends to zero. ↩ - Silver, D., et al. (2016),
Mastering the Game of Go with Deep Neural Networks and Tree Search,
Nature 529:484–489 (AlphaGo) — MCTS combined with a policy network (move priors) and a value network (leaf evaluation), defeating a professional and then the world champion at Go. ↩ - Silver, D., et al. (2018),
A General Reinforcement Learning Algorithm that Masters Chess, Shogi, and Go through Self-Play,
Science 362:1140–1144 (AlphaZero) — self-play with a single value/policy network and a PUCT tree policy, learning Go, chess, and shogi from the rules alone; the search's visit counts serve as the policy-improvement target. ↩ - Schrittwieser, J., et al. (2020),
Mastering Atari, Go, Chess and Shogi by Planning with a Learned Model,
Nature 588:604–609 (MuZero) — running AlphaZero-style MCTS over a learned latent dynamics model, planning without access to the environment's true rules and setting records on Atari. ↩
╌╌ END ╌╌