Struct Game

Source
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

Source

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.

Source

pub fn get_board(&self) -> &Board

Return the game’s board.

Source

pub fn get_current_player(&self) -> Option<Color>

Return the current player, or None if the game has ended.

Source

pub fn get_status(&self) -> Status

Source

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.

Source

pub fn play(&mut self, coords: Coords) -> Result<(), InvalidMove>

Let the current player place a stone at the given coordinates. If the move is invalid, this method returns an error. This method will automatically update the current player.

Trait Implementations§

Source§

impl Clone for Game

Source§

fn clone(&self) -> Game

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
Source§

impl Serialization for Game

Source§

fn save_to_json(&self) -> Value

Save this game as a Serde JSON value
Source§

fn load_from_json(value: Value) -> Result<Self>

Load a game from a Serde JSON value.
Source§

fn save_to_string(&self) -> String

Save this game to a JSON string.
Source§

fn load_from_str(string: &str) -> Result<Self>

Load a game from a JSON string.

Auto Trait Implementations§

§

impl Freeze for Game

§

impl !RefUnwindSafe for Game

§

impl Send for Game

§

impl !Sync for Game

§

impl Unpin for Game

§

impl UnwindSafe for Game

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.