Struct inanis::state::representation::Board
source · 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
impl Board
sourcepub 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
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
sourcepub 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
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
sourcepub 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>
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>
sourcepub 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>
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>
sourcepub fn get_moves<const CAPTURES: bool>(
&self,
moves: &mut [MaybeUninit<Move>; 218],
index: usize,
evasion_mask: u64
) -> usize
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).
sourcepub fn get_all_moves(
&self,
moves: &mut [MaybeUninit<Move>; 218],
evasion_mask: u64
) -> usize
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).
sourcepub fn make_move(&mut self, move: Move)
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
sourcepub fn undo_move(&mut self, move: Move)
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
sourcepub fn make_null_move(&mut self)
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
sourcepub fn undo_null_move(&mut self)
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
sourcepub fn push_state(&mut self)
pub fn push_state(&mut self)
Preserves halfmove clock, castling rights, en passant bitboard, board hash, pawn hash and captured piece on the stack
sourcepub fn pop_state(&mut self)
pub fn pop_state(&mut self)
Restores halfmove clock, castling rights, en passant bitboard, board hash, pawn hash and captured piece from the stack
sourcepub fn is_square_attacked(&self, color: usize, square: usize) -> bool
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.
sourcepub fn are_squares_attacked(&self, color: usize, squares: &[usize]) -> bool
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.
sourcepub fn get_attacking_pieces(&self, color: usize, square: usize) -> usize
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
sourcepub fn is_king_checked(&self, color: usize) -> bool
pub fn is_king_checked(&self, color: usize) -> bool
Check if the king of the color
side is checked.
sourcepub fn get_piece_color(&self, square: usize) -> usize
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.
sourcepub fn add_piece(&mut self, color: usize, piece: usize, square: usize)
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.
sourcepub fn remove_piece(&mut self, color: usize, piece: usize, square: usize)
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.
sourcepub fn move_piece(&mut self, color: usize, piece: usize, from: usize, to: usize)
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.
sourcepub fn recalculate_hashes(&mut self)
pub fn recalculate_hashes(&mut self)
Recalculates board’s hashes entirely.
sourcepub fn evaluate<const DIAG: bool>(
&self,
color: usize,
pawn_hashtable: &PawnHashTable,
statistics: &mut SearchStatistics
) -> i16
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).
sourcepub fn evaluate_without_cache(&self, color: usize) -> i16
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).
sourcepub fn evaluate_lazy(&self, color: usize) -> i16
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).
sourcepub fn recalculate_incremental_values(&mut self)
pub fn recalculate_incremental_values(&mut self)
Recalculates incremental values (material and piece-square tables) entirely.
sourcepub fn is_repetition_draw(&self, threshold: i32) -> bool
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.
sourcepub fn is_fifty_move_rule_draw(&self) -> bool
pub fn is_fifty_move_rule_draw(&self) -> bool
Checks if there’s fifty move rule draw at the current position.
sourcepub fn is_insufficient_material_draw(&self) -> bool
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)
sourcepub fn get_pieces_count(&self) -> u8
pub fn get_pieces_count(&self) -> u8
Gets pieces count by counting set bits in occupancy.