pub struct Board { /* private fields */ }Expand description
The structure for a chessboard/game
Implementations§
Source§impl Board
impl Board
Sourcepub fn move_to_san(&self, move_: Move) -> Result<String, IllegalMoveError>
pub fn move_to_san(&self, move_: Move) -> Result<String, IllegalMoveError>
Represents a Move in SAN, returning an error if the move is illegal.
Sourcepub fn san_to_move(&self, san: &str) -> Result<Move, InvalidSanMoveError>
pub fn san_to_move(&self, san: &str) -> Result<Move, InvalidSanMoveError>
Constructs a Move from a SAN representation, returning an error if it is invalid or illegal.
Sourcepub fn gen_legal_moves(&self) -> Vec<Move>
pub fn gen_legal_moves(&self) -> Vec<Move>
Generates the legal moves in the position.
Sourcepub fn is_capture(&self, move_: Move) -> Result<bool, IllegalMoveError>
pub fn is_capture(&self, move_: Move) -> Result<bool, IllegalMoveError>
Checks whether the given move is a capture, returning an error if the move is illegal.
Sourcepub fn make_move(&mut self, move_: Move) -> Result<(), IllegalMoveError>
pub fn make_move(&mut self, move_: Move) -> Result<(), IllegalMoveError>
Plays on the board the given move, returning an error if the move is illegal.
Sourcepub fn make_move_uci(&mut self, uci: &str) -> Result<(), InvalidUciMoveError>
pub fn make_move_uci(&mut self, uci: &str) -> Result<(), InvalidUciMoveError>
Attempts to parse the UCI representation of a move and play it on the board, returning an error if the move is invalid or illegal.
Sourcepub fn make_move_san(&mut self, san: &str) -> Result<(), InvalidSanMoveError>
pub fn make_move_san(&mut self, san: &str) -> Result<(), InvalidSanMoveError>
Attempts to interpret the SAN representation of a move and play it on the board, returning an error if it is invalid or illegal.
Sourcepub fn make_moves_uci(&mut self, line: &str) -> Result<(), InvalidUciMoveError>
pub fn make_moves_uci(&mut self, line: &str) -> Result<(), InvalidUciMoveError>
Attempts to play the given line of UCI moves (separated by spaces, excluding move numbers) on the board, returning an error if any move is illegal. If an error is returned, the board is left unchanged, i.e. no moves are played on the board.
Sourcepub fn make_moves_san(&mut self, line: &str) -> Result<(), InvalidSanMoveError>
pub fn make_moves_san(&mut self, line: &str) -> Result<(), InvalidSanMoveError>
Attempts to play the given line of SAN moves (separated by spaces, excluding move numbers) on the board, returning an error if any move is illegal. If an error is returned, the board is left unchanged, i.e. no moves are played on the board.
Sourcepub fn undo_move(&mut self) -> Result<(), NoMovesPlayedError>
pub fn undo_move(&mut self) -> Result<(), NoMovesPlayedError>
Undoes the most recent move, returning an error if no moves have been played. Note that if the game had ended, calling this function sets the game to ongoing again. This will override any resignation or draw by agreement.
Sourcepub fn is_ongoing(&self) -> bool
pub fn is_ongoing(&self) -> bool
Checks whether the game is still ongoing.
Sourcepub fn is_game_over(&self) -> bool
pub fn is_game_over(&self) -> bool
Checks whether the game is over.
Sourcepub fn game_result(&self) -> Option<GameResult>
pub fn game_result(&self) -> Option<GameResult>
Returns an optional game result (None if the game is ongoing).
Sourcepub fn halfmove_clock(&self) -> usize
pub fn halfmove_clock(&self) -> usize
Returns the number of halfmoves played since the last pawn push or capture.
Sourcepub fn fullmove_number(&self) -> usize
pub fn fullmove_number(&self) -> usize
Returns the fullmove number.
Sourcepub fn is_threefold_repetition(&self) -> bool
pub fn is_threefold_repetition(&self) -> bool
Checks whether a threefold repetition of the position has occurred.
Sourcepub fn is_fivefold_repetition(&self) -> bool
pub fn is_fivefold_repetition(&self) -> bool
Checks whether a fivefold repetition of the position has occurred.
Sourcepub fn is_fifty_move_rule(&self) -> bool
pub fn is_fifty_move_rule(&self) -> bool
Checks whether a draw can be claimed by the fifty-move rule.
Sourcepub fn is_seventy_five_move_rule(&self) -> bool
pub fn is_seventy_five_move_rule(&self) -> bool
Checks whether the game is drawn by the seventy-five-move rule.
Sourcepub fn is_stalemate(&self) -> bool
pub fn is_stalemate(&self) -> bool
Checks whether the game is drawn by stalemate. Use Board::stalemated_side to know which side is in stalemate.
Sourcepub fn is_insufficient_material(&self) -> bool
pub fn is_insufficient_material(&self) -> bool
Checks whether the game is drawn by insufficient material.
rschess defines insufficient material as any of the following scenarios:
- King and knight vs. king
- King and zero or more bishops vs. king and zero or more bishops where all the bishops are on the same color complex
Sourcepub fn is_sufficient_material(&self) -> bool
pub fn is_sufficient_material(&self) -> bool
Checks whether there is sufficient checkmating material on the board.
Sourcepub fn is_check(&self) -> bool
pub fn is_check(&self) -> bool
Checks whether any side is in check (a checkmate is also considered a check). Use Board::checked_side to know which side is in check.
Sourcepub fn is_checkmate(&self) -> bool
pub fn is_checkmate(&self) -> bool
Checks whether any side is in checkmate. Use Board::checkmated_side to know which side is in checkmate.
Sourcepub fn stalemated_side(&self) -> Option<Color>
pub fn stalemated_side(&self) -> Option<Color>
Returns an optional Color representing the side in stalemate (None if neither side is in stalemate).
Sourcepub fn checked_side(&self) -> Option<Color>
pub fn checked_side(&self) -> Option<Color>
Returns an optional Color representing the side in check (None if neither side is in check).
Sourcepub fn checkmated_side(&self) -> Option<Color>
pub fn checkmated_side(&self) -> Option<Color>
Returns an optional Color representing the side in checkmate (None if neither side is in checkmate).
Sourcepub fn pretty_print(&self, perspective: Color, ascii: bool) -> String
pub fn pretty_print(&self, perspective: Color, ascii: bool) -> String
Pretty-prints the position to a string, from the perspective of the side perspective.
If ascii is true, this function uses piece characters like ‘K’ and ‘p’ instead of
characters like ‘♔’ and ‘♟’.
Sourcepub fn side_to_move(&self) -> Color
pub fn side_to_move(&self) -> Color
Returns which side’s turn it is to move.
Sourcepub fn occupant_of_square(
&self,
file: char,
rank: char,
) -> Result<Option<Piece>, InvalidSquareNameError>
pub fn occupant_of_square( &self, file: char, rank: char, ) -> Result<Option<Piece>, InvalidSquareNameError>
Returns the occupant of a square, or an error if the square name is invalid.
Sourcepub fn resign(&mut self, side: Color) -> Result<(), GameOverError>
pub fn resign(&mut self, side: Color) -> Result<(), GameOverError>
Resigns the game for a certain side, if the game is ongoing. Currently, this function should also be used to represent a loss by timeout.
Sourcepub fn agree_draw(&mut self) -> Result<(), GameOverError>
pub fn agree_draw(&mut self) -> Result<(), GameOverError>
Makes a draw by agreement, if the game is ongoing. Currently, this function should also be used to represent a draw claim.
Sourcepub fn resigned_side(&self) -> Option<Color>
pub fn resigned_side(&self) -> Option<Color>
Returns an optional Color representing the side that has resigned (None if neither side has resigned).
Sourcepub fn draw_agreed(&self) -> bool
pub fn draw_agreed(&self) -> bool
Checks whether a draw has been agreed upon.
Sourcepub fn initial_fen(&self) -> &Fen
pub fn initial_fen(&self) -> &Fen
Returns the initial FEN of the game.
Sourcepub fn gen_movetext(&self) -> String
pub fn gen_movetext(&self) -> String
Generates the SAN movetext of the game thus far (excluding the game result).