Struct backgammon::rules::Board

source ·
pub struct Board { /* private fields */ }
Expand description

Represents the Backgammon board

A Backgammon board consists of 24 fields, each of which can hold 0 or more checkers. In addition there is a bar to hold checkers that have been hit and an off area to hold checkers that have been removed from the board.

//        +12-11-10--9--8--7-------6--5--4--3--2--1-+
//        | X           O    |   | O              X | +-------+
//        | X           O    |   | O              X | | OFF O |
//        | X           O    |   | O                | +-------+
//        | X                |   | O                |
//        | X                |   | O                |
//        |                  |BAR|                  |
//        | O                |   | X                |
//        | O                |   | X                |
//        | O           X    |   | X                | +-------+
//        | O           X    |   | X              O | | OFF X |
//        | O           X    |   | X              O | +-------+
//        +13-14-15-16-17-18------19-20-21-22-23-24-+

Implementations§

source§

impl Board

source

pub fn new() -> Self

Create a new board

source

pub fn get(&self) -> BoardDisplay

Get the board for both players. Use for graphical representation of the board.

This method outputs a tuple with three values:

  1. the board represented as an array of 24 fields, each of which can hold 0 or more checkers. Positive amounts represent checkers of player 0, negative amounts represent checkers of player 1.
  2. the bar for both players
  3. the off for both players
source

pub fn set( &mut self, player: Player, field: usize, amount: i8 ) -> Result<(), Error>

Set checkers for a player on a field

This method adds the amount of checkers for a player on a field. The field is numbered from 0 to 23, starting from the last field of each player in the home board, the most far away field for each player (where there are 2 checkers to start with) is number 23.

If the field is blocked for the player, an error is returned. If the field is not blocked, but there is already one checker from the other player on the field, that checker is hit and moved to the bar.

source

pub fn blocked(&self, player: Player, field: usize) -> Result<bool, Error>

Check if a field is blocked for a player

source

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

Set checkers for a player on the bar

source

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

Set checkers for a player off the board

Trait Implementations§

source§

impl Clone for Board

source§

fn clone(&self) -> Board

Returns a copy 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 Board

source§

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

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

impl Default for Board

source§

fn default() -> Board

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

impl<'de> Deserialize<'de> for Board

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl PartialEq<Board> for Board

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Board

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl StructuralPartialEq for Board

Auto Trait Implementations§

§

impl RefUnwindSafe for Board

§

impl Send for Board

§

impl Sync for Board

§

impl Unpin for Board

§

impl UnwindSafe for Board

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,