pub struct Board {
Show 21 fields pub pieces: [[u64; 6]; 2], pub occupancy: [u64; 2], pub piece_table: [u8; 64], pub castling_rights: u8, pub en_passant: u64, pub halfmove_clock: u16, pub fullmove_number: u16, pub active_color: usize, pub hash: u64, pub pawn_hash: u64, pub null_moves: u8, pub captured_piece: usize, pub game_phase: u8, pub state_stack: Vec<BoardState>, pub material_scores: [i16; 2], pub pst_scores: [[i16; 2]; 2], pub evaluation_parameters: Arc<EvaluationParameters>, pub zobrist: Arc<ZobristContainer>, pub patterns: Arc<PatternsContainer>, pub see: Arc<SEEContainer>, pub magic: Arc<MagicContainer>,
}

Fields§

§pieces: [[u64; 6]; 2]§occupancy: [u64; 2]§piece_table: [u8; 64]§castling_rights: u8§en_passant: u64§halfmove_clock: u16§fullmove_number: u16§active_color: usize§hash: u64§pawn_hash: u64§null_moves: u8§captured_piece: usize§game_phase: u8§state_stack: Vec<BoardState>§material_scores: [i16; 2]§pst_scores: [[i16; 2]; 2]§evaluation_parameters: Arc<EvaluationParameters>§zobrist: Arc<ZobristContainer>§patterns: Arc<PatternsContainer>§see: Arc<SEEContainer>§magic: Arc<MagicContainer>

Implementations§

source§

impl Board

source

pub fn new( evaluation_parameters: Option<Arc<EvaluationParameters>>, zobrist_container: Option<Arc<ZobristContainer>>, patterns_container: Option<Arc<PatternsContainer>>, see_container: Option<Arc<SEEContainer>>, magic_container: Option<Arc<MagicContainer>> ) -> Self

Constructs a new instance of Board, using provided containers. If the parameter is None, then the new container is created.

source

pub fn new_initial_position( evaluation_parameters: Option<Arc<EvaluationParameters>>, zobrist_container: Option<Arc<ZobristContainer>>, patterns_container: Option<Arc<PatternsContainer>>, see_container: Option<Arc<SEEContainer>>, magic_container: Option<Arc<MagicContainer>> ) -> Self

Constructs a new instance of Board with initial position, using provided containers. If the parameter is None, then the new container is created.

source

pub fn new_from_fen( fen: &str, evaluation_parameters: Option<Arc<EvaluationParameters>>, zobrist_container: Option<Arc<ZobristContainer>>, patterns_container: Option<Arc<PatternsContainer>>, see_container: Option<Arc<SEEContainer>>, magic_container: Option<Arc<MagicContainer>> ) -> Result<Self, String>

Constructs a new instance of Board with position specified by fen, using provided containers. If the parameter is None, then the new container is created. Returns Err with proper error message if fen couldn’t be parsed correctly.

source

pub fn new_from_moves( moves: &[&str], evaluation_parameters: Option<Arc<EvaluationParameters>>, zobrist_container: Option<Arc<ZobristContainer>>, patterns_container: Option<Arc<PatternsContainer>>, see_container: Option<Arc<SEEContainer>>, magic_container: Option<Arc<MagicContainer>> ) -> Result<Self, String>

Constructs a new instance of Board with position specified by list of moves, using provided containers. If the parameter is None, then the new container is created. Returns Err with proper error message is moves couldn’t be parsed correctly.

source

pub fn get_moves<const CAPTURES: bool>( &self, moves: &mut [MaybeUninit<Move>; 218], index: usize, evasion_mask: u64 ) -> usize

Generates all possible non-captures (if CAPTURES is false) or all possible captures (if CAPTURES is true) at the current position, stores them into moves list (starting from index) and returns index of the first free slot. Use evasion_mask with value different than u64::MAX to restrict generator to the specified squares (useful during checks).

source

pub fn get_all_moves( &self, moves: &mut [MaybeUninit<Move>; 218], evasion_mask: u64 ) -> usize

Generates all possible moves (non-captures and captures) at the current position, stores them into moves list (starting from index) and returns index of the first free slot. Use evasion_mask with value different than u64::MAX to restrict generator to the specified squares (useful during checks).

source

pub fn make_move(&mut self, move: Move)

Makes r#move, with the assumption that it’s perfectly valid at the current position (otherwise, internal state can be irreversibly corrupted).

Steps of making a move:

  • preserve halfmove clock, castling rights, en passant bitboard, board hash and pawn hash
  • update piece bitboards
  • update board hash and pawn hash
  • update en passant bitboard if needed
  • update castling rights if needed
  • increase fullmove number if needed
  • increase halfmove clock if needed
  • switch active color
source

pub fn undo_move(&mut self, move: Move)

Undoes r#move, with the assumption that it’s perfectly valid at the current position (otherwise, internal state can be irreversibly corrupted).

Steps of undoing a move:

  • update piece bitboards
  • decrease fullmove number if needed
  • restore halfmove clock if needed
  • switch active color
  • restore halfmove clock, castling rights, en passant bitboard, board hash and pawn hash
source

pub fn make_null_move(&mut self)

Makes a null move, which is basically a switch of the active color with preservation of the internal state.

Steps of making a null move:

  • preserve halfmove clock, castling rights, en passant bitboard, board hash and pawn hash
  • update en passant bitboard if needed
  • increase fullmove number if needed
  • increase null moves count
  • switch active color
source

pub fn undo_null_move(&mut self)

Undoes a null move, which is basically a switch of the active color with restoring of the internal state.

Steps of undoing a null move:

  • decrease fullmove number if needed
  • switch active color
  • decrease null moves count
  • restore halfmove clock, castling rights, en passant bitboard, board hash and pawn hash
source

pub fn push_state(&mut self)

Preserves halfmove clock, castling rights, en passant bitboard, board hash, pawn hash and captured piece on the stack

source

pub fn pop_state(&mut self)

Restores halfmove clock, castling rights, en passant bitboard, board hash, pawn hash and captured piece from the stack

source

pub fn is_square_attacked(&self, color: usize, square: usize) -> bool

Checks if the square specified by square is attacked by enemy, from the color perspective.

source

pub fn are_squares_attacked(&self, color: usize, squares: &[usize]) -> bool

Checks if any of the square specified by squares list is attacked by enemy, from the color perspective.

source

pub fn get_attacking_pieces(&self, color: usize, square: usize) -> usize

Gets a list of enemy pieces attacking a square specified by squares_index, from the color perspective. The encoding looks as follows:

  • bit 0 - Pawn
  • bit 1, 2, 3 - Knight/Bishop
  • bit 4, 5 - Rook
  • bit 6 - Queen
  • bit 7 - King
source

pub fn is_king_checked(&self, color: usize) -> bool

Check if the king of the color side is checked.

source

pub fn get_piece(&self, square: usize) -> usize

Gets piece on the square specified by square.

source

pub fn get_piece_color(&self, square: usize) -> usize

Gets piece’s color on the square specified by square. Returns u8::MAX if there is no piece there.

source

pub fn add_piece(&mut self, color: usize, piece: usize, square: usize)

Adds piece on the square with the specified color, also updates occupancy and incremental values.

source

pub fn remove_piece(&mut self, color: usize, piece: usize, square: usize)

Removes piece on the square with the specified color, also updates occupancy and incremental values.

source

pub fn move_piece(&mut self, color: usize, piece: usize, from: usize, to: usize)

Moves piece from the square specified by from to the square specified by to with the specified color, also updates occupancy and incremental values.

source

pub fn recalculate_hashes(&mut self)

Recalculates board’s hashes entirely.

source

pub fn evaluate<const DIAG: bool>( &self, color: usize, pawn_hashtable: &PawnHashTable, statistics: &mut SearchStatistics ) -> i16

Runs full evaluation (material, piece-square tables, mobility, pawns structure and safety) of the current position, using pawn_hashtable to store pawn evaluations and statistics to gather diagnostic data. Returns score from the color perspective (more than 0 when advantage, less than 0 when disadvantage).

source

pub fn evaluate_without_cache(&self, color: usize) -> i16

Runs full evaluation (material, piece-square tables, mobility, pawns structure and safety) of the current position. Returns score from the color perspective (more than 0 when advantage, less than 0 when disadvantage).

source

pub fn evaluate_lazy(&self, color: usize) -> i16

Runs lazy (fast) evaluations, considering only material and piece-square tables. Returns score from the color perspective (more than 0 when advantage, less than 0 when disadvantage).

source

pub fn recalculate_incremental_values(&mut self)

Recalculates incremental values (material and piece-square tables) entirely.

source

pub fn is_repetition_draw(&self, threshold: i32) -> bool

Checks if there’s repetition draw with the specified threshold (should be 3 in the most cases) at the current position.

source

pub fn is_fifty_move_rule_draw(&self) -> bool

Checks if there’s fifty move rule draw at the current position.

source

pub fn is_insufficient_material_draw(&self) -> bool

Checks if there’s an inssuficient material draw:

  • King vs King
  • King + Knight/Bishop vs King
  • King + Bishop (same color) vs King + Bishop (same color)
source

pub fn get_pieces_count(&self) -> u8

Gets pieces count by counting set bits in occupancy.

source

pub fn get_instant_move(&mut self) -> Option<Move>

Checks if there’s an instant move possible and returns it as Some, otherwise None.

source

pub fn get_tablebase_move(&self, probe_limit: u32) -> Option<(Move, i16)>

Checks if there’s a tablebase move (only Syzygy supported for now) and returns it as Some, otherwise None.

source

pub fn to_fen(&self) -> String

Converts the board’s state into FEN.

source

pub fn to_epd(&self) -> String

Converts the board`s state into EPD.

Trait Implementations§

source§

impl Clone for Board

source§

fn clone(&self) -> Board

Returns a copy 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 Display for Board

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Board

§

impl Send for Board

§

impl Sync for Board

§

impl Unpin for Board

§

impl UnwindSafe for Board

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.