# turnbase-bots - Complete API Documentation > Search and policy bots for the Turnbase engine (random, minimax, MCTS) **Version:** 0.0.0 **Authors:** Matan Lurey **License:** MIT OR Apache-2.0 **Repository:** https://github.com/crates-lurey-io/turnbase **Keywords:** game-engine, turn-based, deterministic, gamedev, ai Generated: 2026-07-25 17:07:54 UTC Created by: [cargo-llms-txt](https://github.com/masinc/cargo-llms-txt) ## Table of Contents ### src/minimax.rs - pub struct Minimax - impl Minimax - impl Bot for Minimax - impl RankedBot for Minimax ### src/ismcts.rs - pub struct Ismcts - impl Ismcts - impl Node - impl Bot for Ismcts - impl RankedBot for Ismcts ### src/lib.rs - pub use ismcts::Ismcts - pub use mcts::Mcts - pub use minimax::Minimax - pub use random::Random - pub trait Bot - pub trait RankedBot ### src/mcts.rs - pub struct Mcts - impl Mcts - impl Node - impl Bot for Mcts - impl RankedBot for Mcts ### src/random.rs - pub struct Random - impl Random - impl Bot for Random --- ## README.md ### turnbase-bots Search and policy bots for the Turnbase engine (random, minimax, MCTS) Part of the [turnbase](https://github.com/crates-lurey-io/turnbase) workspace. --- ## src/minimax.rs ### Minimax ```rust pub struct Minimax { } ``` Depth-limited alpha-beta minimax. Assumes exactly one active player per node (sequential play) and two-player zero-sum outcomes. Leaves are evaluated with [`Game::reward`], so give the search enough depth to reach terminals (or a game whose `reward` doubles as a heuristic at non-terminal nodes). Two search paths are offered and always agree: [`Minimax::best_action`] clones state per node (needs `State: Clone`), and [`Minimax::best_action_unmake`] uses a game's [`Reversible`] make/unmake. ### impl Minimax ```rust impl Minimax { pub fn new(max_depth: u32) -> Self; pub fn best_action(&self, game: &G, state: &G::State, player: PlayerId) -> Option where G: Game, G::State: Clone, G::Action: Clone; pub fn best_action_unmake(&self, game: &G, state: &mut G::State, player: PlayerId) -> Option where G: Reversible, G::Action: Clone; } ``` ### impl Bot for Minimax ```rust impl Bot for Minimax { } ``` ### impl RankedBot for Minimax ```rust impl RankedBot for Minimax { } ``` ## src/ismcts.rs ### Ismcts ```rust pub struct Ismcts { } ``` Single-observer information-set MCTS for hidden-information games. Standard [`Mcts`](crate::Mcts) cheats at hidden information: it searches the one true state, so it sees opponents' secret cards. ISMCTS instead searches from a player's *information set*. Each simulation asks the game for a fresh determinization ([`Determinize::determinize`]) — a full world consistent with what the searcher can see, but with the hidden parts resampled — and runs one UCT iteration in that world. Averaging over many sampled worlds yields a move that is good on expectation without ever peeking. A single tree is shared across determinizations. Because different worlds offer different legal moves, selection uses an *availability* count (how many simulations a move was legal for) in the UCB denominator, and only moves legal in the current world are considered. Values are backed up as a vector, one entry per seat, and each node selects to maximize the mover's own entry (`max^n`), so this handles three- and four-player games, not just two-player zero-sum. Rollouts are uniform-random. All randomness comes from an internal seeded generator, so a run is reproducible. ### impl Ismcts ```rust impl Ismcts { pub fn new(iterations: u32, seed: u64) -> Self; pub fn with_exploration(self, exploration: f64) -> Self; pub fn evaluate(&mut self, game: &G, state: &G::State, player: PlayerId) -> f64 where G: Determinize, G::State: Clone, G::Action: Clone; } ``` ### impl Node ```rust impl Node { } ``` ### impl Bot for Ismcts ```rust impl Bot for Ismcts { } ``` ### impl RankedBot for Ismcts ```rust impl RankedBot for Ismcts { } ``` ## src/lib.rs ### ismcts::Ismcts ```rust pub use ismcts::Ismcts; ``` ### mcts::Mcts ```rust pub use mcts::Mcts; ``` ### minimax::Minimax ```rust pub use minimax::Minimax; ``` ### random::Random ```rust pub use random::Random; ``` ### Bot ```rust pub trait Bot { fn choose(&mut self, game: &G, state: &G::State, player: PlayerId) -> Option; } ``` A policy that picks one action for a player at a decision point. ### RankedBot ```rust pub trait RankedBot { fn rank(&mut self, game: &G, state: &G::State, player: PlayerId) -> Vec<(G::Action, f64)>; } ``` A bot that scores and ranks every available action, best first. For hints, teaching, and debugging search. An opt-in extension to [`Bot`]: bots with no meaningful ranking (e.g. a uniform-random bot) simply do not implement it. ## src/mcts.rs ### Mcts ```rust pub struct Mcts { } ``` UCT Monte Carlo tree search for sequential games, with chance nodes. Assumes exactly one active player per decision node (like [`Minimax`]) and two-player zero-sum outcomes. All node values are kept from a fixed root player's perspective: the root maximizes, the opponent minimizes (a sign flip in selection), and chance nodes average their sampled children, which is exactly the expectiminimax behavior. Chance nodes are descended by sampling [`Game::chance_outcomes`], never by UCT. Rollouts are uniform-random. Randomness (rollouts and chance sampling) comes from an internal seeded generator, so a run is reproducible. [`Minimax`]: crate::Minimax ### impl Mcts ```rust impl Mcts { pub fn new(iterations: u32, seed: u64) -> Self; pub fn with_exploration(self, exploration: f64) -> Self; pub fn evaluate(&mut self, game: &G, state: &G::State, player: PlayerId) -> f64 where G: Game, G::State: Clone, G::Action: Clone; } ``` ### impl Node ```rust impl Node { } ``` ### impl Bot for Mcts ```rust impl Bot for Mcts { } ``` ### impl RankedBot for Mcts ```rust impl RankedBot for Mcts { } ``` ## src/random.rs ### Random ```rust pub struct Random { } ``` Picks uniformly at random among the legal actions. Deterministic given its seed: the same seed and the same sequence of positions produce the same choices, which keeps games reproducible. ### impl Random ```rust impl Random { pub fn new(seed: u64) -> Self; } ``` ### impl Bot for Random ```rust impl Bot for Random { } ```