Skip to main content

MonteCarloBot

Struct MonteCarloBot 

Source
pub struct MonteCarloBot<R: Rng> { /* private fields */ }
Expand description

A determinized Monte Carlo player

At every decision the bot samples hidden worlds consistent with its View — the opponent holds every card they are known to have taken, and the remaining unseen cards are distributed between their hand and the stock, biased toward the meld-rich hands a real opponent collects — plays each world out with the greedy policy on both seats, and picks the action with the best expected value for the game: each rollout’s result lands on the running game scores, a result that reaches game_target counts as the win or loss of the game it is, and anything short of one counts its round points. The same worlds are reused across candidate actions (common random numbers), and the bot deviates from the greedy baseline only when the paired samples show a statistically clear gain.

The bot owns its random number generator, so a seeded generator makes its play reproducible.

Implementations§

Source§

impl<R: Rng> MonteCarloBot<R>

Source

pub const fn new(rng: R) -> Self

A bot with default strength: 128 worlds per decision, 4 candidate discards

Source

pub const fn samples(self, samples: u32) -> Self

Set how many worlds each decision samples

More samples play stronger and slower. At the default of 128 the bot wins about 65% of decisive rounds against the default HeuristicBot — which is tuned for whole-game play and so concedes single rounds — at ~10 ms per turn in release builds; 32 keeps a smaller edge at a quarter of the cost.

Source

pub const fn max_candidates(self, max_candidates: usize) -> Self

Set how many candidate discards play_turn evaluates

Trait Implementations§

Source§

impl<R: Rng> Strategy for MonteCarloBot<R>

Source§

fn offer_upcard(&mut self, view: &View<'_>) -> UpcardAction

Take or pass the initial upcard
Source§

fn choose_draw(&mut self, view: &View<'_>) -> DrawAction

Draw from the stock or the discard pile Read more
Source§

fn play_turn(&mut self, view: &View<'_>) -> TurnAction

Discard, knock, or declare big gin Read more
Source§

fn choose_layoff(&mut self, view: &View<'_>) -> Option<Layoff>

Lay one card off onto the knocker’s spread, or None to finish Read more
Source§

fn name(&self) -> &str

A display name for tournament output

Auto Trait Implementations§

§

impl<R> Freeze for MonteCarloBot<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for MonteCarloBot<R>
where R: RefUnwindSafe,

§

impl<R> Send for MonteCarloBot<R>
where R: Send,

§

impl<R> Sync for MonteCarloBot<R>
where R: Sync,

§

impl<R> Unpin for MonteCarloBot<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for MonteCarloBot<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for MonteCarloBot<R>
where R: UnwindSafe,

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.