[−][src]Struct chess::Game
For UI/UCI Servers, store a game object which allows you to determine draw by 3 fold repitition, draw offers, resignations, and moves.
This structure is slow compared to using Board
directly, so it is
not recommended for engines.
Methods
impl Game
[src]
pub fn new() -> Game
[src]
Create a new Game
with the initial position.
use chess::{Game, Board}; let game = Game::new(); assert_eq!(game.current_position(), Board::default());
pub fn actions(&self) -> &Vec<Action>
[src]
Get all actions made in this game (moves, draw offers, resignations, etc.)
use chess::{Game, MoveGen, Color}; let mut game = Game::new(); let mut movegen = MoveGen::new_legal(&game.current_position()); game.make_move(movegen.next().expect("At least one valid move")); game.resign(Color::Black); assert_eq!(game.actions().len(), 2);
pub fn result(&self) -> Option<GameResult>
[src]
What is the status of this game?
use chess::Game; let game = Game::new(); assert!(game.result().is_none());
pub fn new_from_fen(fen: &str) -> Option<Game>
[src]
Create a new Game
object from an FEN string.
use chess::{Game, Board}; let game = Game::new_from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1").expect("Valid FEN"); let game2 = Game::new_from_fen("Invalid FEN"); assert!(game2.is_none());
pub fn current_position(&self) -> Board
[src]
Get the current position on the board from the Game
object.
use chess::{Game, Board}; let game = Game::new(); assert_eq!(game.current_position(), Board::default());
pub fn can_declare_draw(&self) -> bool
[src]
Determine if a player can legally declare a draw by 3-fold repetition or 50-move rule.
use chess::{Game, Square, Rank, File, ChessMove}; let b1 = Square::make_square(Rank::First, File::B); let c3 = Square::make_square(Rank::Third, File::C); let b8 = Square::make_square(Rank::Eighth, File::B); let c6 = Square::make_square(Rank::Sixth, File::C); let b1c3 = ChessMove::new(b1, c3, None); let c3b1 = ChessMove::new(c3, b1, None); let b8c6 = ChessMove::new(b8, c6, None); let c6b8 = ChessMove::new(c6, b8, None); let mut game = Game::new(); assert_eq!(game.can_declare_draw(), false); game.make_move(b1c3); game.make_move(b8c6); game.make_move(c3b1); game.make_move(c6b8); assert_eq!(game.can_declare_draw(), false); // position has shown up twice game.make_move(b1c3); game.make_move(b8c6); game.make_move(c3b1); game.make_move(c6b8); assert_eq!(game.can_declare_draw(), true); // position has shown up three times
pub fn declare_draw(&mut self) -> bool
[src]
Declare a draw by 3-fold repitition or 50-move rule.
use chess::{Game, Square, Rank, File, ChessMove}; let b1 = Square::make_square(Rank::First, File::B); let c3 = Square::make_square(Rank::Third, File::C); let b8 = Square::make_square(Rank::Eighth, File::B); let c6 = Square::make_square(Rank::Sixth, File::C); let b1c3 = ChessMove::new(b1, c3, None); let c3b1 = ChessMove::new(c3, b1, None); let b8c6 = ChessMove::new(b8, c6, None); let c6b8 = ChessMove::new(c6, b8, None); let mut game = Game::new(); assert_eq!(game.can_declare_draw(), false); game.make_move(b1c3); game.make_move(b8c6); game.make_move(c3b1); game.make_move(c6b8); assert_eq!(game.can_declare_draw(), false); // position has shown up twice game.make_move(b1c3); game.make_move(b8c6); game.make_move(c3b1); game.make_move(c6b8); assert_eq!(game.can_declare_draw(), true); // position has shown up three times game.declare_draw();
pub fn make_move(&mut self, chess_move: ChessMove) -> bool
[src]
Make a chess move on the board
use chess::{Game, MoveGen}; let mut game = Game::new(); let mut movegen = MoveGen::new_legal(&game.current_position()); game.make_move(movegen.next().expect("At least one legal move"));
pub fn side_to_move(&self) -> Color
[src]
Who's turn is it to move?
use chess::{Game, Color}; let game = Game::new(); assert_eq!(game.side_to_move(), Color::White);
pub fn offer_draw(&mut self, color: Color) -> bool
[src]
Offer a draw to my opponent. color
is the player who offered the draw. The draw must be
accepted before my opponent moves.
use chess::{Game, Color}; let mut game = Game::new(); game.offer_draw(Color::White);
pub fn accept_draw(&mut self) -> bool
[src]
Accept a draw offer from my opponent.
use chess::{Game, MoveGen, Color}; let mut game = Game::new(); game.offer_draw(Color::Black); assert_eq!(game.accept_draw(), true); let mut game2 = Game::new(); let mut movegen = MoveGen::new_legal(&game2.current_position()); game2.offer_draw(Color::Black); game2.make_move(movegen.next().expect("At least one legal move")); assert_eq!(game2.accept_draw(), false);
pub fn resign(&mut self, color: Color) -> bool
[src]
color
resigns the game
use chess::{Game, Color}; let mut game = Game::new(); game.resign(Color::White);
Trait Implementations
impl Clone for Game
[src]
fn clone(&self) -> Game
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Debug for Game
[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,