Skip to main content

turnbase_bots/
lib.rs

1//! Bots for the Turnbase engine: `Random`, minimax/alpha-beta, and MCTS.
2//!
3//! Every bot drives a game through the [`turnbase::Game`] trait, so the same
4//! bot works for any game implemented against the engine.
5
6use turnbase::{Game, PlayerId};
7
8mod ismcts;
9mod mcts;
10mod minimax;
11mod random;
12
13pub use ismcts::Ismcts;
14pub use mcts::Mcts;
15pub use minimax::Minimax;
16pub use random::Random;
17
18/// A policy that picks one action for a player at a decision point.
19pub trait Bot<G: Game> {
20    /// Returns the action to play for `player` in `state`, or `None` if there
21    /// is nothing to do (no legal actions, e.g. a terminal state).
22    fn choose(&mut self, game: &G, state: &G::State, player: PlayerId) -> Option<G::Action>;
23}
24
25/// A bot that scores and ranks every available action, best first.
26///
27/// For hints, teaching, and debugging search. An opt-in extension to [`Bot`]:
28/// bots with no meaningful ranking (e.g. a uniform-random bot) simply do not
29/// implement it.
30pub trait RankedBot<G: Game> {
31    /// Returns each legal action for `player` paired with its score, sorted
32    /// best (highest score) first. Empty when there are no legal actions.
33    fn rank(&mut self, game: &G, state: &G::State, player: PlayerId) -> Vec<(G::Action, f64)>;
34}