pub struct Game { /* private fields */ }Expand description
§The Backgammon Game
This struct holds all the fields necessary to play a single round of Backgammon. The implemented methods for this struct are the ones required to play a single round of Backgammon, e.g. enforcing the right player and other game rules.
Caveat: Even though you can theoretically play one Backgammon game correctly on the Game struct, it is not suggested to operate directly on this struct. To correctly apply all double cube rules, it is recommended to use the Match struct.
// +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§
Trait Implementations§
Source§impl Move for Game
impl Move for Game
Source§fn get_board(&self) -> BoardDisplay
fn get_board(&self) -> BoardDisplay
Returns the current board.
Source§fn set_checkers(
&mut self,
player: Player,
to: Position,
amount: i8,
) -> Result<(), Error>
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.
Updates the game state by moving a player’s checkers to a new position on the board based on the specified amount. This function handles various scenarios such as moving checkers to specific board fields, the bar, or off the board. The method is incremental, i.e. it adds or subtracts (if negative amounts are used) the existing checkers on the respective positions.