Skip to main content

State

Struct State 

Source
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

Source

pub const START: Self

The empty card at the start of a game.

Source

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.

Source

pub const fn scored(self) -> Categories

The filled categories.

Source

pub const fn upper(self) -> u8

The upper-section subtotal, capped at the bonus threshold of 63.

Source

pub const fn yahtzee_50(self) -> bool

Whether the Yahtzee box holds 50, enabling 100-point bonuses and joker values for further Yahtzees.

Source

pub const fn is_full(self) -> bool

Whether every category is filled and the game is over.

Source

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.

Source

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.

Source

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:

  1. the matching upper box, if open, is the only legal category;
  2. otherwise any open lower box, at full joker value;
  3. otherwise any open upper box, for zero.

The result is non-empty unless the card is full.

Source

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§

Source§

impl Clone for State

Source§

fn clone(&self) -> State

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for State

Source§

impl Debug for State

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for State

Source§

impl Hash for State

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for State

Source§

fn eq(&self, other: &State) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.