Skip to main content

GameState

Struct GameState 

Source
pub struct GameState { /* private fields */ }
Expand description

The full game state: board, whose turn it is, move counter, and outcome.

Implementations§

Source§

impl GameState

Source

pub fn new() -> Self

Creates a new game with the standard FULL_HEXO configuration.

Source

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.

Source

pub fn apply_move(&mut self, coord: Coord) -> Result<(), MoveError>

Attempts to place the current player’s stone at coord.

Source

pub fn legal_moves(&self) -> Vec<Coord>

Returns all legal moves for the current position, sorted lexicographically.

Source

pub fn legal_move_count(&self) -> usize

Returns the number of legal moves without allocating.

Source

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.

Source

pub fn is_terminal(&self) -> bool

Returns true when the game has ended (win or draw).

Source

pub fn winner(&self) -> Option<Player>

Returns the winner, or None if there is no winner (game ongoing or draw).

Source

pub fn current_player(&self) -> Option<Player>

Returns the player who should move next, or None if the game is over.

Source

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.

Source

pub fn placed_stones(&self) -> Vec<(Coord, Player)>

Returns all placed stones as (coord, player) pairs.

Source

pub fn move_count(&self) -> u32

Returns the total number of moves made so far (not counting P1’s opening stone).

Source

pub fn config(&self) -> &GameConfig

Returns a reference to the game configuration.

Trait Implementations§

Source§

impl Clone for GameState

Source§

fn clone(&self) -> GameState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 T
where T: Clone,

Source§

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

Source§

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

Source§

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.