Unit 10 of 11 · about 3 hours · implement

Monte Carlo Tree Search

MCTS focuses simulation where earlier simulations looked promising. It is the planner behind the game-playing results and the template for search with learned models.

You'll be able to

  • Implement the four MCTS steps (selection, expansion, simulation, backup) with a tree policy and a rollout policy.
  • Apply UCB selection inside the tree by hand on a fixed visit-count case.
  • State when MCTS is the right planner: a fast simulatable model with time for many rollouts per move.

Covers

Monte Carlo Tree Search
1

Read

In this order, only the parts listed

0 of 3 done

  1. Chapter 8, Section 8.11: Monte Carlo Tree SearchReinforcement Learning: An Introduction (2nd ed.) - Chapter 8

    Section 8.11, printed pp. 185 to 187: rollout-algorithm base, the four steps with Figure 8.10, UCB tree policy, final action by value or visit count

    Implement the basic four-step version. The authors post the full text free at incompleteideas.net; the URL above is the publisher page.

  2. Search and World Models: AlphaZero loopHands-on Modern RL - Model-Based and World-Model Sections

    The Core AlphaZero Loop with the PUCT formula and Self-Play Training (page read 2026-10-14)

    Use for the neural plus search vocabulary only. Simulation counts and match results (800 simulations, Stockfish, Go) are author-reported history, not runnable targets.

  3. Lecture 11: Model-Based RL, game-planning slideStanford CS224R Spring 2026 - Model-Based RL

    Slide 29: AlphaGo (known rules, 1 to 40 move horizon with terminal value, policy narrows the search, value trained by Monte Carlo regression)

2

Focus on

  • MCTS is a rollout algorithm with memory. Selection and expansion grow a tree over the promising prefix; simulation completes episodes with the rollout policy; backup updates only the tree edges the tree policy traversed.
  • Inside the tree, actions come from a UCB-style tree policy balancing value and visit counts. Beyond the tree, actions come from the (possibly random) rollout policy, and those states save nothing.
  • The delivered action is a function of root statistics (best value or most visits), and the next move reruns the whole process from the new state, optionally keeping the surviving subtree.
Common mistakes · 3
  • Backing up values into states visited only by the rollout policy. Only tree edges traversed by the tree policy are updated; rollout states beyond the tree save nothing.
  • Applying UCB to unvisited actions. With the bonus divides by zero; expand untried actions first instead of scoring them.
  • Picking the final action by noisy value when visit counts disagree. The book offers the most-visited root action as the choice that avoids selecting outliers.
3

Try it yourself

Closed-book, before checking anything

From a blank file, implement selection, expansion, simulation and backup on tic-tac-toe or a small gridworld with a known model. Separately, hand-compute UCB with at a node with 10 visits and children and : scores 1.7111 and 1.8390, so selection picks the less-visited child despite its lower value. Match both numbers.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Why is MCTS called a rollout algorithm with memory?Answer

    Each iteration runs a rollout-style simulation from the current state, but the tree accumulates value estimates across iterations and steers later simulations toward promising prefixes.

  2. 2.In the hand case above, why does selection pick the child with fewer visits?Answer

    Its UCB score 1.8390 exceeds 1.7111: the larger exploration bonus for 3 visits against 7 outweighs the 0.3 value gap, which is exactly the intended explore-exploit trade.

  3. 3.What do the policy and value networks contribute in AlphaZero's MCTS?Answer

    The policy prior narrows search width toward promising actions and the value network evaluates leaves directly, cutting the depth the search must reach.

  4. 4.When is MCTS the wrong planner for a learned model?Answer

    When one model step is slow or the budget allows few simulations per move: MCTS needs fast multistep simulation and many rollouts to focus the tree.

You're done when

Your four-step implementation runs on a small game, your hand UCB numbers match, and you can state the per-move simulation budget your result rests on.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 5 more in the section
  • Reinforcement Learning: An Introduction (2nd ed.) - Chapter 8Richard Sutton and Andrew Barto · required

    The authors post the full second edition free at incompleteideas.net; cite the printed page numbers. Study Sections 8.1 to 8.3 (models, Dyna-Q, when the model is wrong) and Sections 8.8 to 8.11 (decision-time planning, rollout algorithms and Monte Carlo Tree Search). Reproduce the Dyna-Q versus Dyna-Q+ ranking on the blocking or shortcut maze.

  • Stanford CS224R Spring 2026 - Model-Based RLStanford University · support

    Use Lecture 11 (model-based RL) and its MBPO reading as a second treatment of model error, uncertainty and short model rollouts.

  • Hands-on Modern RL - Model-Based and World-Model SectionsWalking Labs · support

    Use Sections 9.3 and 9.4 as concept maps for model-based RL, search and world models. No runnable dynamics or planner script exists, so reproduce its error-recursion numbers by hand and verify algorithm claims against the original papers. Pin commit 9231bab of walkinglabs/hands-on-modern-rl; its code/chapterNN folders do not follow the site chapter numbers.

Also in this section

  • Berkeley CS 185/285 Deep Reinforcement Learning (Spring 2026) - Model-Based RLUC Berkeley · primary

    Slides are public at https://rail.eecs.berkeley.edu/deeprlcourse/static/slides/lec-N.pdf; current videos are not, and the public Fall 2023 playlist numbers lectures differently. Study Lectures 15 and 16 (model-based RL: learned dynamics, open-loop and closed-loop planning, random shooting and CEM, MPC, model-based policy learning). There is no model-based homework, so build the planner yourself on a small environment with known dynamics first.

  • When to Trust Your Model: Model-Based Policy OptimizationJanner et al. · required

    Study the model-error analysis and short model-rollout design. Reproduce a reduced real-plus-imagined-data comparison and retain the horizon where model bias reverses the gain.

  • Deep Reinforcement Learning in a Handful of Trials using Probabilistic Dynamics Models (PETS)Chua et al. (NeurIPS 2018) · support

    Read the split between aleatoric uncertainty (probabilistic networks) and epistemic uncertainty (ensembles) and the trajectory-sampling planner. Implement an ensemble on a small task and show where the members disagree.

  • Mastering Diverse Domains through World ModelsDeepMind · depth

    Read DreamerV3 only after the small explicit dynamics and planning path passes. Trace representation, latent dynamics, imagination and actor-critic state, but do not make a large benchmark reproduction part of the exit gate.

  • Reinforcement Learning Control Laboratory - Model-Based StretchRoadmap-Final · support

    Add a learned-dynamics stretch with a known-dynamics sanity case, prediction and planning tests, horizon sweeps, model-exploitation failure and matched model-free comparison.