AI Grounds

Open AI Grounds on a desktop

These interactive lessons need a larger screen. Please continue on a desktop or laptop computer.

Guided discovery

Monte Carlo Tree Search

Choose a branch, read a scripted result, and update its visited path.

Scripted mechanics demo

This is a small demonstration of selection and backpropagation, not a game solver. All three illustrations share generic branches A–D and repeating scripted outcomes. No legal moves, deeper tree expansion or random game rollout is implemented.

c gives the exploration bonus more or less weight. Editing a control pauses Run; counts stay fixed. Use arrow keys on the slider. Press Enter or leave the number field to apply an exact edit.

Includes the 64 seeded visits. Lowering the budget stops without undoing evidence. Use arrow keys on the slider. Press Enter or leave the number field to apply an exact edit.

64 total visits = 64 seeded + 0 new steps. 1 remaining. Ready.

Next selection · branch D

score = Q + c × sqrt(ln N / n)

Q is successes / visits. N is parent visits; n is branch visits. ln is the natural logarithm. At fixed N and c, fewer visits give a larger bonus. UCB means upper confidence bound; here the score is a selection priority, can exceed 1, and is not a win probability or proof.

Current branch scores · two-decimal display; selection uses full precision. Ties use A–D order.
BranchSuccesses / visitsQBonusScoreMeaning
A27 / 380.710.461.17Best observed Q
B8 / 140.570.761.33Wait
C3 / 90.330.951.29Wait
D1 / 30.331.651.98Next selection

Best observed Q: A. This describes the record. Next selection chooses where to sample next; neither label is a final move recommendation.

Root and four existing branches

Dashed outline: next selection. Solid orange path and “Last”: last completed Step. Counts are successes / visits. The diagram adds no child nodes.

Root39 / 64Branch A27 / 38Branch B8 / 14Branch C3 / 9Branch D1 / 3Next

Root · 39 / 64

↓ Four existing child branches

Branch A27 / 38Not visited last

Branch B8 / 14Not visited last

Branch C3 / 9Not visited last

Branch D1 / 3Next

Root Q = 39 / 64 = 0.61. Root counts sum the child counts, so its Q is weighted by visits, not an equal average of four branch Q values.

Last completed update

No new result yet. Press Step to create a recorded update. The seeded counts are teaching fixtures, not a reconstructed game history.

What full MCTS adds
  1. Selection follows a policy down an existing tree.
  2. Expansion adds a legal successor at an expandable node.
  3. Simulation plays out or evaluates that state to produce a reward.
  4. Backpropagation updates the visited path from the reward.

This demo implements root selection and a two-node count backup. It substitutes repeating 0/1 outcome scripts for simulation and has no expansion, terminal game rules or alternating player perspective. Repeated scripts are not independent random samples, so Monte Carlo convergence guarantees do not apply. A real implementation must specify game rules, rollout policy, reward viewpoint and final-action rule.

An unvisited branch gets priority ∞ in this engine and is selected before visited ones; all four provided branches begin visited. Q is displayed as 0 for an unvisited branch as a placeholder, not a reward estimate.

Browne et al. · A Survey of Monte Carlo Tree Search Methods
Illustration and result scripts

A board sketch only: A–D are generic branches, not legal Tic Tac Toe moves. Changing an illustration does not change the search record or outcome scripts.

X O X O X · · · ·

Each branch repeats its listed script. The next result uses the branch’s pre-Step visit count modulo script length as a zero-based index, including seeded visits.

  • Branch A: 1, 1, 0, 1, 1, 0, 1, 1 · next index 6
  • Branch B: 1, 0, 1, 0, 1, 1 · next index 2
  • Branch C: 0, 1, 0, 0, 1 · next index 4
  • Branch D: 1, 0, 1, 1, 0, 1 · next index 3