Skip to main content

Board

Struct Board 

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

The structure for a chessboard/game

Implementations§

Source§

impl Board

Source

pub fn from_fen(fen: Fen) -> Self

Constructs a Board from a Fen object.

Source

pub fn to_fen(&self) -> Fen

Returns a Fen object representing the Board.

Source

pub fn move_to_san(&self, move_: Move) -> Result<String, IllegalMoveError>

Represents a Move in SAN, returning an error if the move is illegal.

Source

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.

Generates the legal moves in the position.

Checks whether a move is legal in the position.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn is_ongoing(&self) -> bool

Checks whether the game is still ongoing.

Source

pub fn is_game_over(&self) -> bool

Checks whether the game is over.

Source

pub fn game_result(&self) -> Option<GameResult>

Returns an optional game result (None if the game is ongoing).

Source

pub fn halfmove_clock(&self) -> usize

Returns the number of halfmoves played since the last pawn push or capture.

Source

pub fn fullmove_number(&self) -> usize

Returns the fullmove number.

Source

pub fn is_threefold_repetition(&self) -> bool

Checks whether a threefold repetition of the position has occurred.

Source

pub fn is_fivefold_repetition(&self) -> bool

Checks whether a fivefold repetition of the position has occurred.

Source

pub fn is_fifty_move_rule(&self) -> bool

Checks whether a draw can be claimed by the fifty-move rule.

Source

pub fn is_seventy_five_move_rule(&self) -> bool

Checks whether the game is drawn by the seventy-five-move rule.

Source

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.

Source

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
Source

pub fn is_sufficient_material(&self) -> bool

Checks whether there is sufficient checkmating material on the board.

Source

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.

Source

pub fn is_checkmate(&self) -> bool

Checks whether any side is in checkmate. Use Board::checkmated_side to know which side is in checkmate.

Source

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

Returns an optional Color representing the side in stalemate (None if neither side is in stalemate).

Source

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

Returns an optional Color representing the side in check (None if neither side is in check).

Source

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

Returns an optional Color representing the side in checkmate (None if neither side is in checkmate).

Source

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 ‘♟’.

Source

pub fn side_to_move(&self) -> Color

Returns which side’s turn it is to move.

Source

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.

Source

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.

Source

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.

Source

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

Returns an optional Color representing the side that has resigned (None if neither side has resigned).

Source

pub fn draw_agreed(&self) -> bool

Checks whether a draw has been agreed upon.

Source

pub fn initial_fen(&self) -> &Fen

Returns the initial FEN of the game.

Source

pub fn gen_movetext(&self) -> String

Generates the SAN movetext of the game thus far (excluding the game result).

Source

pub fn position(&self) -> &Position

Returns the current Position on the board.

Trait Implementations§

Source§

impl Clone for Board

Source§

fn clone(&self) -> Board

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Board

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Board

Source§

fn default() -> Self

Constructs a Board with the starting position for a chess game.

Source§

impl Display for Board

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Pretty-prints the position on the board from the perspective of the side whose turn it is to move.

Source§

impl Eq for Board

Source§

impl Hash for Board

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Board

Source§

fn eq(&self, other: &Board) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Board

Auto Trait Implementations§

§

impl Freeze for Board

§

impl RefUnwindSafe for Board

§

impl Send for Board

§

impl Sync for Board

§

impl Unpin for Board

§

impl UnsafeUnpin for Board

§

impl UnwindSafe for Board

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.