Skip to main content

Minimax

Struct Minimax 

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

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.

Implementations§

Source§

impl Minimax

Source

pub const fn new(max_depth: u32) -> Self

Creates a search that looks up to max_depth plies ahead.

Source

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

Returns the value-maximizing action for player using cloned search.

Source

pub fn best_action_unmake<G>( &self, game: &G, state: &mut G::State, player: PlayerId, ) -> Option<G::Action>
where G: Reversible, G::Action: Clone,

Returns the value-maximizing action for player using make/unmake.

Mutates state during the search but restores it exactly, so state is unchanged on return.

Trait Implementations§

Source§

impl<G> Bot<G> for Minimax
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 Minimax
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)>

Scores each root action with a full alpha-beta window (no cross-sibling pruning), so every score is the move’s exact minimax value rather than a bound. Costlier than Minimax::best_action; use it for analysis, not hot self-play.

Auto Trait Implementations§

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.