pub struct Game { /* private fields */ }Expand description
A game of Yahtzee for one or more players.
Players act in seat order, thirteen rounds each. The primitive input
is deterministic dice injection — roll takes the
complete five-die result, which makes replays and front ends trivial
and keeps the rules free of randomness. Game::roll_with rolls for
you behind the rand feature.
Illegal inputs are rejected with a GameError and leave the game
unchanged, so interactive callers can simply retry.
Implementations§
Source§impl Game
impl Game
Sourcepub const fn rolls_left(&self) -> u8
pub const fn rolls_left(&self) -> u8
How many rolls remain this turn: 3 before the first roll, 0 after the third (when only scoring is left) and once the game is over.
Sourcepub const fn kept(&self) -> Keep
pub const fn kept(&self) -> Keep
The dice held for the pending roll; empty at the start of a turn.
Sourcepub fn scorecards(&self) -> &[Scorecard]
pub fn scorecards(&self) -> &[Scorecard]
All cards in seat order.
Sourcepub fn roll(&mut self, dice: Dice) -> Result<(), GameError>
pub fn roll(&mut self, dice: Dice) -> Result<(), GameError>
Resolves the pending roll with a complete five-die result, which must contain the held dice.
§Errors
GameError::Finished, GameError::ActionPending, or
GameError::KeptNotHeld if dice dropped a held die.
Sourcepub fn roll_with<R: Rng + ?Sized>(
&mut self,
rng: &mut R,
) -> Result<Dice, GameError>
pub fn roll_with<R: Rng + ?Sized>( &mut self, rng: &mut R, ) -> Result<Dice, GameError>
Rolls the unheld dice with rng and resolves the pending roll.
§Errors
Sourcepub fn act(
&mut self,
action: TurnAction,
) -> Result<Option<ScoreDelta>, GameError>
pub fn act( &mut self, action: TurnAction, ) -> Result<Option<ScoreDelta>, GameError>
Applies the acting player’s decision: hold and reroll, or score.
Scoring returns the ScoreDelta and advances to the next seat;
a reroll returns None and awaits the next roll.
§Errors
GameError::Finished, GameError::RollPending,
GameError::NoRerollsLeft, GameError::KeepNotInDice, or
GameError::IllegalCategory; the game is left unchanged.
Trait Implementations§
impl Eq for Game
impl StructuralPartialEq for Game
Auto Trait Implementations§
impl Freeze for Game
impl RefUnwindSafe for Game
impl Send for Game
impl Sync for Game
impl Unpin for Game
impl UnsafeUnpin for Game
impl UnwindSafe for Game
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