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. Worlds are rolled in growing batches, and a challenger the incumbent already statistically dominates is dropped at a batch boundary — once none remain, the remaining worlds are never rolled at all — so an easy decision costs a fraction of the full sample count.

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

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 roughly 10 ms per average turn in release builds (easy decisions stop at a fraction of the budget; a hard first discard, where every shed stays plausible, runs the full count for ~25 ms); 32 keeps a smaller edge at a quarter of the cost. The parallel feature divides any of these by most of a machine’s cores.

Source

pub fn assess(&mut self, view: &View<'_>) -> Vec<Assessment>

Assess every candidate action for the current decision, each with its Monte Carlo equity and expected round points, ranked by equity with the bot’s own pick flagged — the read a solver or hint view shows

The candidates and the flagged pick mirror the matching Strategy method on the same sampled worlds, so the recommended row is the move the bot would play — with one deliberate contraction: a knock’s shed is not a real choice (dropping the largest deadwood is always the best knock), so the discard phase lists a single knock rather than one per shed. Returns empty when the seat has no real choice: a forced stock draw, the layoff phase, or a finished round.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.