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
impl Board
sourcepub fn get(&self) -> BoardDisplay
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:
- 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.
- the bar for both players
- the off for both players
sourcepub fn set(
&mut self,
player: Player,
field: usize,
amount: i8
) -> Result<(), Error>
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.
sourcepub fn blocked(&self, player: Player, field: usize) -> Result<bool, Error>
pub fn blocked(&self, player: Player, field: usize) -> Result<bool, Error>
Check if a field is blocked for a player