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
sourceimpl 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.
Trait Implementations
sourceimpl Serialization for Game
impl Serialization for Game
sourcefn save_to_json(&self) -> Value
fn save_to_json(&self) -> Value
Save this game as a Serde JSON value
sourcefn load_from_json(value: Value) -> Result<Self>
fn load_from_json(value: Value) -> Result<Self>
Load a game from a Serde JSON value.
sourcefn save_to_string(&self) -> String
fn save_to_string(&self) -> String
Save this game to a JSON string.
sourcefn load_from_str(string: &str) -> Result<Self>
fn load_from_str(string: &str) -> Result<Self>
Load a game from a JSON string.
Auto Trait Implementations
impl !RefUnwindSafe for Game
impl Send for Game
impl !Sync for Game
impl Unpin for Game
impl UnwindSafe for Game
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more