v2026.6.1
All Bundles
Bundle Classic AI algorithms: graph search, adversarial game search, optimization and tabular reinforcement learning (-lib ai)

MonteCarloTreeSearch

Monte Carlo tree search (UCT) over a GameState. Each playout selects by the UCB1 rule, expands one node, plays uniformly random moves to the end (or the rollout cap) and backs the evaluation up the tree. Seeded for reproducible searches; the most-visited root child is returned.

Example

mcts := MonteCarloTreeSearch->New(2000, 1.414, 7);
best := mcts->FindBestMove(state);

Operations

FindBestMove #

Finds the best move for the player to move.

method : public : FindBestMove(state:GameState) ~ Int

Parameters

NameTypeDescription
stateGameStateposition to search

Return

TypeDescription
Intbest move id, or -1 when no moves exist

New # constructor

Constructor

New(playouts:Int, exploration:Float, seed:Int)

Parameters

NameTypeDescription
playoutsIntnumber of playouts per search
explorationFloatUCB1 exploration constant (typically ~1.4)
seedIntPRNG seed for reproducible searches