pub struct Board {
    pub pieces: [[u64; 6]; 2],
    pub occupancy: [u64; 2],
    pub piece_table: [u8; 64],
    pub fullmove_number: u16,
    pub stm: usize,
    pub null_moves: u8,
    pub game_phase: u8,
    pub state: BoardState,
    pub state_stack: Vec<BoardState>,
    pub pawn_attacks: [u64; 2],
}

Fields§

§pieces: [[u64; 6]; 2]§occupancy: [u64; 2]§piece_table: [u8; 64]§fullmove_number: u16§stm: usize§null_moves: u8§game_phase: u8§state: BoardState§state_stack: Vec<BoardState>§pawn_attacks: [u64; 2]

Implementations§

source§

impl Board

source

pub fn new_initial_position() -> Self

Constructs a new instance of Board with initial position.

source

pub fn new_from_fen(fen: &str) -> Result<Self, String>

Constructs a new instance of Board. Returns Err with proper error message if fen couldn’t be parsed correctly.

source

pub fn new_from_moves(moves: &[&str]) -> Result<Self, String>

Constructs a new instance of Board with position specified by list of moves. Returns Err with proper error message is moves couldn’t be parsed correctly.

source

pub fn get_moves<const CAPTURES: bool>( &self, moves: &mut Moves, 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 Moves, 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 board state
  • update piece bitboards
  • update board hash and pawn hash
  • update en passant bitboard
  • update castling rights
  • update piece-square table scores
  • update pawn attacks
  • increase fullmove number
  • increase halfmove clock
  • 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
  • update pawn attacks
  • decrease fullmove number
  • switch active color
  • restore board state
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 board state
  • update en passant bitboard
  • increase fullmove number
  • 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
  • switch active color
  • decrease null moves count
  • restore board state
source

pub fn push_state(&mut self)

Preserves internal board state.

source

pub fn pop_state(&mut self)

Restores internal board state.

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 usize::MAX if there is no piece there.

source

pub fn add_piece<const UNDO: bool>( &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<const UNDO: bool>( &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<const UNDO: bool>( &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 recalculate_pawn_attacks(&mut self, color: usize)

Recalculate pawn attacks for the specific color.

source

pub fn evaluate( &self, color: usize, phtable: &PHTable, stats: &mut SearchStats ) -> i16

Runs full evaluation (material, piece-square tables, mobility, pawn structure and safety) of the current position, using phtable to store pawn evaluations and stats 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, pawn 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_fast( &self, color: usize, phtable: &PHTable, stats: &mut SearchStats ) -> i16

Runs fast evaluations, considering only material, piece-square tables and pawn structure. 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 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 insufficient 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 Default for Board

source§

fn default() -> Self

Returns the “default value” for a type. 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 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> 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,

§

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§

default 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>,

§

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>,

§

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.