pub struct State { /* private fields */ }Expand description
Everything about a scorecard that affects future play.
Only three facts matter for legality and expected value: which
categories are filled, the upper-section subtotal capped at the bonus
threshold of 63, and whether the Yahtzee box holds 50 (the gate for
the 100-point bonus). Box-by-box history is display data and lives in
Scorecard; the solver keys its value table on
this type via State::index.
Implementations§
Source§impl State
impl State
Sourcepub const fn new(scored: Categories, upper: u8, yahtzee_50: bool) -> Self
pub const fn new(scored: Categories, upper: u8, yahtzee_50: bool) -> Self
Builds a state, clamping to consistency: upper is capped at what
the scored upper categories can total (and at 63), and
yahtzee_50 is cleared unless the Yahtzee box is scored.
Sourcepub const fn scored(self) -> Categories
pub const fn scored(self) -> Categories
The filled categories.
Sourcepub const fn upper(self) -> u8
pub const fn upper(self) -> u8
The upper-section subtotal, capped at the bonus threshold of 63.
Sourcepub const fn yahtzee_50(self) -> bool
pub const fn yahtzee_50(self) -> bool
Whether the Yahtzee box holds 50, enabling 100-point bonuses and joker values for further Yahtzees.
Sourcepub const fn index(self) -> usize
pub const fn index(self) -> usize
A perfect 20-bit hash: category bits, then the capped upper
subtotal, then the Yahtzee-50 flag. Always below 1 << 20.
Sourcepub const fn from_index(index: usize) -> Option<Self>
pub const fn from_index(index: usize) -> Option<Self>
Rebuilds a state from Self::index.
Returns None for indices that violate the invariants: an upper
subtotal beyond what the scored upper categories can total (or
beyond the 63 cap), or a Yahtzee-50 flag without the Yahtzee box
scored.
Sourcepub fn legal_categories(self, dice: Dice) -> Categories
pub fn legal_categories(self, dice: Dice) -> Categories
The categories dice may legally be scored in, applying joker
forcing for extra Yahtzees.
Normally every open category is legal (scoring zero is always allowed). When the roll is a Yahtzee but the Yahtzee box is already filled — with 50 or zero — the forced-joker rule restricts the choice:
- the matching upper box, if open, is the only legal category;
- otherwise any open lower box, at full joker value;
- otherwise any open upper box, for zero.
The result is non-empty unless the card is full.
Sourcepub fn apply(self, category: Category, dice: Dice) -> Option<ScoreDelta>
pub fn apply(self, category: Category, dice: Dice) -> Option<ScoreDelta>
Scores dice in category: the written value, bonuses, and the
next state.
Returns None if category is not in
legal_categories. An extra Yahtzee
scores joker values in the lower section (Full House 25, Small
Straight 30, Large Straight 40, the rest the dice total) and earns
the 100-point bonus whenever the Yahtzee box holds 50, even on a
forced zero.
Trait Implementations§
impl Copy for State
impl Eq for State
impl StructuralPartialEq for State
Auto Trait Implementations§
impl Freeze for State
impl RefUnwindSafe for State
impl Send for State
impl Sync for State
impl Unpin for State
impl UnsafeUnpin for State
impl UnwindSafe for State
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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