Skip to main content

Match

Struct Match 

Source
pub struct Match { /* private fields */ }
Expand description

Represents a Backgammon match.

A match is a series of games played until a player reaches the predefined number of points.

Implementations§

Source§

impl Match

Implements methods for the Match struct

Source

pub fn new() -> Self

Start a new match:

use backgammon::Match;

let m = Match::new();
Source

pub fn offer_double(&mut self, player: Player) -> Result<(), Error>

Offer the cube to the other player.

Source

pub fn accept_double(&mut self, player: Player) -> Result<(), Error>

After a double has been offered, the other player can accept it.

Source

pub fn reject_double(&mut self, player: Player) -> Result<(), Error>

After a double has been offered, the other player can reject it.

Source

pub fn get_state(&self) -> Result<&MatchState, Error>

Return the current state of the match.

Source

pub fn get_player(&self) -> Result<Player, Error>

Return the current player, i.e. the player who needs to perform an action.

Trait Implementations§

Source§

impl Clone for Match

Source§

fn clone(&self) -> Match

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Match

Source§

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

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

impl Default for Match

Source§

fn default() -> Match

Returns the “default value” for a type. Read more
Source§

impl MatchRules for Match

Source§

fn set_points(&mut self, points: u64) -> Result<(), Error>

Set the number of points required to win the match.
Source§

fn get_points(&self) -> Result<u64, Error>

Get the number of points required to win the match.
Source§

fn set_cube_play(&mut self, cube: bool) -> Result<(), Error>

Set the cube status.
Source§

fn get_cube_play(&self) -> Result<bool, Error>

Get the cube status.
Source§

fn set_crawford(&mut self, state: bool) -> Result<(), Error>

Apply the Crawford rule: if the first player reaches a score of points - 1, no doubling is allowed for the following game.
Source§

fn get_crawford(&self) -> Result<bool, Error>

Get the Crawford rule status.
Source§

fn set_beaver(&mut self, state: bool) -> Result<(), Error>

Apply the Beaver rule: if offered the cube, allow to re-double but keep it.
Source§

fn get_beaver(&self) -> Result<bool, Error>

Get the Beaver rule status.
Source§

fn set_raccoon(&mut self, state: bool) -> Result<(), Error>

Apply the Raccoon rule: if a player beavered the offered cube, the other may double again, letting the player keep the cube. This requires the Crawford rule to be enabled.
Source§

fn get_raccoon(&self) -> Result<bool, Error>

Get the Raccoon rule status.
Source§

fn set_murphy(&mut self, state: bool, limit: u8) -> Result<(), Error>

Apply the Murphy rule: if both players roll the same opening number, the cube is doubled, remaining in the middle of the board. The limit parameter defines how often to apply the automatic doubling rule in a Murphy game. 0 means always on.
Source§

fn get_murphy(&self) -> Result<(bool, u8), Error>

Get the Murphy rule status and the limit setting. A limit of 0 means that the Murphy rule is always on, given the rule is enabled.
Source§

fn set_jacobi(&mut self, state: bool) -> Result<(), Error>

Apply the Jacobi rule: Gammon and Backgammon only count for double or triple values if the cube has already been offered.
Source§

fn get_jacobi(&self) -> Result<bool, Error>

Get the Jacobi rule status.
Source§

fn set_holland(&mut self, state: bool) -> Result<(), Error>

Apply the Holland rule: Permits to double after the Crawford game only if both players have rolled at least twice. Requires the Crawford rule to be enabled.
Source§

fn get_holland(&self) -> Result<bool, Error>

Get the Holland rule status.
Source§

impl Move for Match

Source§

fn get_board(&self) -> BoardDisplay

Get the current board in a human-readable format.
Source§

fn move_checkers( &mut self, player: Player, moves: Vec<(Position, Position)>, ) -> Result<(), Error>

Move a sequence of checkers from a given position to another position. Read more
Source§

fn set_checkers( &mut self, player: Player, to: Position, amount: i8, ) -> Result<(), Error>

Set a number of checkers at a given position. This method can be used to prepare a board. Read more
Source§

fn empty_board(&mut self) -> Result<(), Error>

Empty the board.
Source§

fn available_moves( &self, player: Player, ) -> Result<Vec<Vec<(Position, Position)>>, Error>

Return all available checker moves for a given player and a given set of available (not already used) dice.
Source§

impl Roll for Match

Source§

fn roll(&mut self, player: Player) -> Result<(), Error>

Roll the two dice.
Source§

fn get_dice(&self) -> (u8, u8)

Get the current values of the dice.
Source§

fn set_dice(&mut self, player: Player, v: (u8, u8)) -> Result<(), Error>

Set the values of the dice.
Source§

fn dice_available(&self) -> &Vec<u8>

Returns the available dice values. These are the dice not yet consumed by a move.
Source§

fn dice_consumed(&self) -> bool

Return true if all dice have been consumed and no die is available for playing.

Auto Trait Implementations§

§

impl Freeze for Match

§

impl RefUnwindSafe for Match

§

impl Send for Match

§

impl Sync for Match

§

impl Unpin for Match

§

impl UnsafeUnpin for Match

§

impl UnwindSafe for Match

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> 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.