pub struct GameState { /* private fields */ }Expand description
The full game state: board, whose turn it is, move counter, and outcome.
Implementations§
Source§impl GameState
impl GameState
Sourcepub fn with_config(config: GameConfig) -> Self
pub fn with_config(config: GameConfig) -> Self
Creates a new game with a custom configuration.
P1’s first stone is placed at (0,0) by Board::new().
The game starts with P2 to move with 2 moves remaining.
§Panics
Panics if win_length < 2, placement_radius < 1, or max_moves < 1.
Sourcepub fn apply_move(&mut self, coord: Coord) -> Result<(), MoveError>
pub fn apply_move(&mut self, coord: Coord) -> Result<(), MoveError>
Attempts to place the current player’s stone at coord.
Sourcepub fn legal_moves(&self) -> Vec<Coord> ⓘ
pub fn legal_moves(&self) -> Vec<Coord> ⓘ
Returns all legal moves for the current position, sorted lexicographically.
Sourcepub fn legal_move_count(&self) -> usize
pub fn legal_move_count(&self) -> usize
Returns the number of legal moves without allocating.
Sourcepub fn legal_moves_set(&self) -> &HashSet<Coord>
pub fn legal_moves_set(&self) -> &HashSet<Coord>
Returns a reference to the internal legal moves set. Iteration order is arbitrary (not sorted). Use this on hot paths where sorting is unnecessary.
Sourcepub fn is_terminal(&self) -> bool
pub fn is_terminal(&self) -> bool
Returns true when the game has ended (win or draw).
Sourcepub fn winner(&self) -> Option<Player>
pub fn winner(&self) -> Option<Player>
Returns the winner, or None if there is no winner (game ongoing or draw).
Sourcepub fn current_player(&self) -> Option<Player>
pub fn current_player(&self) -> Option<Player>
Returns the player who should move next, or None if the game is over.
Sourcepub fn moves_remaining_this_turn(&self) -> u8
pub fn moves_remaining_this_turn(&self) -> u8
Returns how many moves the current player has left this turn. Returns 0 when the game is over.
Sourcepub fn placed_stones(&self) -> Vec<(Coord, Player)>
pub fn placed_stones(&self) -> Vec<(Coord, Player)>
Returns all placed stones as (coord, player) pairs.
Sourcepub fn move_count(&self) -> u32
pub fn move_count(&self) -> u32
Returns the total number of moves made so far (not counting P1’s opening stone).
Sourcepub fn config(&self) -> &GameConfig
pub fn config(&self) -> &GameConfig
Returns a reference to the game configuration.