pub struct Game { /* private fields */ }
Expand description
Game
holds the full state of a game of Hex and allows to manipulate this state by playing valid moves.
The game state consists of a board (get_board
) and the current player (get_current_player
).
Implementations§
Source§impl Game
impl Game
Sourcepub fn new(size: CoordValue) -> Game
pub fn new(size: CoordValue) -> Game
Create a new game with the given board size. Boards are always square.
Games always start with black.
This method will panic if the size is not bounded by MIN_BOARD_SIZE
and MAX_BOARD_SIZE
.
Sourcepub fn get_current_player(&self) -> Option<Color>
pub fn get_current_player(&self) -> Option<Color>
Return the current player, or None if the game has ended.
pub fn get_status(&self) -> Status
Sourcepub fn load(
stones: StoneMatrix,
current_player: Option<Color>,
) -> Result<Self, InvalidBoard>
pub fn load( stones: StoneMatrix, current_player: Option<Color>, ) -> Result<Self, InvalidBoard>
Load a game from a StoneMatrix
and a current player color.
This method returns an error if current_player
is None, but the game has not yet finished.
Conversely, if the game has finished, current_player
will be ignored.
Please also have a look at the Serialization
trait which allows to directly deserialize a game from JSON.