Monte Carlo Tree Search (MCTS)

GATE Relevance: Medium

Prerequisites

🎯 Learning Objectives

  • Understand the four phases of MCTS: Selection, Expansion, Simulation, Backpropagation
  • Apply the UCB1 formula for balancing exploration and exploitation
  • Explain why MCTS works well for Go and other games with large branching factors
  • Know how AlphaGo/AlphaZero combined MCTS with neural networks

1. Why MCTS?

For games like Go (b ≈ 250, m ≈ 150), even alpha-beta with evaluation functions is insufficient — the branching factor is too high and designing a good evaluation function for Go proved extremely difficult. MCTS takes a radically different approach: use random simulations to estimate move quality.

Monte Carlo Tree Search

MCTS is an anytime best-first search algorithm that builds a search tree incrementally and uses random playouts (simulations) to evaluate positions. It does not require a hand-crafted evaluation function.

2. The Four Phases

Each MCTS iteration consists of four steps, repeated thousands or millions of times:

Phase 1: Selection

Starting from the root, use a tree policy (e.g., UCB1) to traverse the current tree, choosing the most promising nodes until reaching a leaf node of the current tree.

Phase 2: Expansion

Add one or more child nodes to the selected leaf, representing an unexplored move from that state.

Phase 3: Simulation (Rollout)

From the newly expanded node, play a random game to completion (or use a lightweight heuristic). This is called a playout or rollout. Returns +1 (win), 0 (draw), or −1 (loss) for the root player.

Phase 4: Backpropagation

Propagate the simulation result back up the tree from the expanded node to the root, updating visit counts and win counts at each ancestor node.

MCTS Iteration Diagram
  SELECTION          EXPANSION       SIMULATION      BACKPROPAGATION
     (A)                (A)             (A)               (A) 
    / \               / \             / \               / \  
  (B)  (C)          (B)  (C)       (B)  (C)          (B)  (C)
  /                 /               /                 /      
(D)               (D)             (D)               (D)     
                    \               \                 \      
                    [E]             [E]               [E]    
                    new         random playout    update stats
                    node        from E → end     E→D→B→A

3. UCB1: Balancing Exploration and Exploitation

UCB1 (Upper Confidence Bound 1)

The selection phase uses the UCB1 formula to choose which child to visit:

UCB1(i) = wi / ni + C · √(ln N / ni)

  • wi = number of wins after the i-th child
  • ni = number of visits to the i-th child
  • N = total number of visits to the parent
  • C = exploration constant (typically √2, tuned per application)

The formula has two terms:

  • Exploitation term (wi/ni): Favor nodes with high win rates
  • Exploration term (C√(ln N / ni)): Favor nodes that have been visited less often
UCB1 Calculation Example
Root visited N = 100 times. Three children:
  Child A: 40 visits, 22 wins  → UCB1 = 22/40 + √2 ·√(ln100/40)
         = 0.550 + 1.414 × 0.339 = 0.550 + 0.479 = 1.029
  Child B: 35 visits, 20 wins  → UCB1 = 20/35 + √2 ·√(ln100/35)
         = 0.571 + 1.414 × 0.362 = 0.571 + 0.512 = 1.083
  Child C: 25 visits, 10 wins  → UCB1 = 10/25 + √2 ·√(ln100/25)
         = 0.400 + 1.414 × 0.429 = 0.400 + 0.607 = 1.007

Selection: Choose Child B (highest UCB1 = 1.083)
  B wins due to good win rate AND moderate visit count.

4. Complete MCTS Algorithm

Algorithm: MCTS(root_state, max_iterations)
function MCTS(root_state, max_iterations):
    root ← new Node(root_state)
    for i = 1 to max_iterations:
        node ← SELECT(root)           // Phase 1
        child ← EXPAND(node)           // Phase 2
        result ← SIMULATE(child.state)  // Phase 3
        BACKPROPAGATE(child, result)     // Phase 4
    return child of root with highest visit count

function SELECT(node):
    while node is fully expanded AND not terminal:
        node ← child of node with best UCB1
    return node

function EXPAND(node):
    action ← random unexplored action from node.state
    child_state ← RESULT(node.state, action)
    child ← new Node(child_state, parent=node)
    return child

function SIMULATE(state):
    while not IS-TERMINAL(state):
        action ← random action from ACTIONS(state)
        state ← RESULT(state, action)
    return UTILITY(state)

function BACKPROPAGATE(node, result):
    while node ≠ null:
        node.visits += 1
        node.wins += result (from node's player perspective)
        node ← node.parent
Final Move Selection

After all iterations, the best move is chosen based on visit count (most robust), not win rate. The most-visited child has the most statistical support.

5. Properties of MCTS

PropertyMCTSMinimax + Alpha-Beta
Evaluation functionNot required (uses playouts)Required for cutoff search
AnytimeYes (returns best move found so far)With iterative deepening
Branching factor sensitivityHandles very large bPerformance degrades with large b
Asymptotic convergenceConverges to minimax with ∞ iterationsExact minimax (full depth)
ParallelismHighly parallelizable (root, leaf, tree parallelization)Harder to parallelize
Best forGo, complex strategy gamesChess, checkers

6. Applications: AlphaGo and Beyond

AlphaGo (DeepMind, 2016)

AlphaGo combined MCTS with deep neural networks:

  • Policy network: Trained on human expert games to predict likely moves → guides SELECTION phase (replaces random action choice)
  • Value network: Trained via self-play to evaluate board positions → replaces random SIMULATION with learned evaluation
  • MCTS integrates both networks to search effectively with b ≈ 250
  • Defeated world champion Lee Sedol 4–1 in March 2016
AlphaZero (DeepMind, 2017)

AlphaZero generalized the approach:

  • Learned entirely from self-play (no human data)
  • Single neural network outputs both policy (move probabilities) and value
  • Mastered Go, Chess, and Shogi from scratch within hours
  • Surpassed Stockfish in chess after just 4 hours of training
GATE Tip

For GATE, know the four phases, the UCB1 formula, and why MCTS works for high-branching-factor games. You may be asked to compute UCB1 values or identify the correct phase order.

Summary

  • MCTS builds a search tree incrementally using random simulations.
  • Four phases: Selection (UCB1), Expansion, Simulation (rollout), Backpropagation.
  • UCB1 balances exploitation (high win rate) and exploration (less visited).
  • No evaluation function needed — playouts provide value estimates.
  • Especially powerful for games with large branching factors (Go: b ≈ 250).
  • AlphaGo/AlphaZero enhanced MCTS with neural network policy and value functions.

References

  • Russell, S. & Norvig, P. AIMA, 4th Ed. — Chapter 5.4
  • Browne, C. et al. “A Survey of Monte Carlo Tree Search Methods”, IEEE TCIAIG, 2012
  • Silver, D. et al. “Mastering the Game of Go with Deep Neural Networks and Tree Search”, Nature, 2016
  • Silver, D. et al. “A General Reinforcement Learning Algorithm that Masters Chess, Shogi, and Go”, Science, 2018