Struct inanis::state::representation::Board
source · 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
impl Board
sourcepub fn new_initial_position() -> Self
pub fn new_initial_position() -> Self
Constructs a new instance of Board with initial position.
sourcepub fn new_from_fen(fen: &str) -> Result<Self, String>
pub fn new_from_fen(fen: &str) -> Result<Self, String>
sourcepub fn new_from_moves(moves: &[&str]) -> Result<Self, String>
pub fn new_from_moves(moves: &[&str]) -> Result<Self, String>
sourcepub fn get_moves<const CAPTURES: bool>(
&self,
moves: &mut Moves,
index: usize,
evasion_mask: u64
) -> usize
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).
sourcepub fn get_all_moves(&self, moves: &mut Moves, evasion_mask: u64) -> usize
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).
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 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
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
- update pawn attacks
- decrease fullmove number
- switch active color
- restore board state
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 board state
- update en passant bitboard
- increase fullmove number
- 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
- switch active color
- decrease null moves count
- restore board state
sourcepub fn push_state(&mut self)
pub fn push_state(&mut self)
Preserves internal board state.
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 usize::MAX
if there is no piece there.
sourcepub fn add_piece<const UNDO: bool>(
&mut self,
color: usize,
piece: usize,
square: usize
)
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.
sourcepub fn remove_piece<const UNDO: bool>(
&mut self,
color: usize,
piece: usize,
square: usize
)
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.
sourcepub fn move_piece<const UNDO: bool>(
&mut self,
color: usize,
piece: usize,
from: usize,
to: usize
)
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.
sourcepub fn recalculate_hashes(&mut self)
pub fn recalculate_hashes(&mut self)
Recalculates board’s hashes entirely.
sourcepub fn recalculate_pawn_attacks(&mut self, color: usize)
pub fn recalculate_pawn_attacks(&mut self, color: usize)
Recalculate pawn attacks for the specific color
.
sourcepub fn evaluate(
&self,
color: usize,
phtable: &PHTable,
stats: &mut SearchStats
) -> i16
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).
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, pawn 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_fast(
&self,
color: usize,
phtable: &PHTable,
stats: &mut SearchStats
) -> i16
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).
sourcepub fn recalculate_incremental_values(&mut self)
pub fn recalculate_incremental_values(&mut self)
Recalculates incremental values 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 insufficient 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.