Skip to main content

Mcts

Struct Mcts 

Source
pub struct Mcts { /* private fields */ }
Expand description

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.

Implementations§

Source§

impl Mcts

Source

pub const fn new(iterations: u32, seed: u64) -> Self

Creates a search running iterations simulations per move, seeded from seed. Uses the standard UCT exploration constant (sqrt 2).

Source

pub const fn with_exploration(self, exploration: f64) -> Self

Sets the UCT exploration constant (higher explores more).

Source

pub fn evaluate<G>( &mut self, game: &G, state: &G::State, player: PlayerId, ) -> f64
where G: Game, G::State: Clone, G::Action: Clone,

Estimates the value of state for player as the mean rollout reward, searching from player’s perspective. Works even when the root is a chance node (no decision to make), unlike Bot::choose.

Trait Implementations§

Source§

impl<G> Bot<G> for Mcts
where G: Game, G::State: Clone, G::Action: Clone,

Source§

fn choose( &mut self, game: &G, state: &G::State, player: PlayerId, ) -> Option<G::Action>

Returns the action to play for player in state, or None if there is nothing to do (no legal actions, e.g. a terminal state).
Source§

impl<G> RankedBot<G> for Mcts
where G: Game, G::State: Clone, G::Action: Clone,

Source§

fn rank( &mut self, game: &G, state: &G::State, player: PlayerId, ) -> Vec<(G::Action, f64)>

Ranks root actions by visit share (the MCTS-recommended policy). Scores are the fraction of simulations spent on each move and sum to 1.

Auto Trait Implementations§

§

impl Freeze for Mcts

§

impl RefUnwindSafe for Mcts

§

impl Send for Mcts

§

impl Sync for Mcts

§

impl Unpin for Mcts

§

impl UnsafeUnpin for Mcts

§

impl UnwindSafe for Mcts

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.