pub struct Board {
pub turn: Team,
pub state: State,
}Expand description
The main game board combining piece positions and current turn.
Fields§
§turn: TeamThe current team’s turn.
state: StateThe state of the board.
Implementations§
Source§impl Board
impl Board
Sourcepub fn actions_into(&self, actions: &mut Vec<Action>)
pub fn actions_into(&self, actions: &mut Vec<Action>)
Computes the valid actions and stores them in the provided Vec.
The Vec is cleared before adding actions. This allows callers to reuse a Vec across multiple calls without manual clearing.
Sourcepub fn count_actions(&self, scratch: &mut Vec<Action>) -> u64
pub fn count_actions(&self, scratch: &mut Vec<Action>) -> u64
Counts the number of valid actions using the provided scratch buffer.
This is faster than actions_into when you only need the count,
particularly useful for bulk leaf counting in perft at depth 1.
Returns 0 for terminal positions (no actions available).
Source§impl Board
impl Board
Sourcepub const fn new_default() -> Self
pub const fn new_default() -> Self
Creates a new board with default configuration.
Sourcepub const fn from_squares(
turn: Team,
white_squares: &[Square],
black_squares: &[Square],
king_squares: &[Square],
) -> Self
pub const fn from_squares( turn: Team, white_squares: &[Square], black_squares: &[Square], king_squares: &[Square], ) -> Self
Creates a new board from the given squares.
Sourcepub const fn friendly_pieces(&self) -> u64
pub const fn friendly_pieces(&self) -> u64
Returns the friendly pieces.
Sourcepub const fn hostile_pieces(&self) -> u64
pub const fn hostile_pieces(&self) -> u64
Returns the hostile pieces.
Sourcepub const fn swap_turn_(&mut self)
pub const fn swap_turn_(&mut self)
Swaps the player’s turn in-place.
Sourcepub fn apply(&self, action: &Action) -> Self
pub fn apply(&self, action: &Action) -> Self
Applies the given action to the board and returns the new board.
Sourcepub fn status(&self) -> GameStatus
pub fn status(&self) -> GameStatus
Computes the status of the board.
Source§impl Board
impl Board
Sourcepub fn perft(&self, depth: u64) -> u64
pub fn perft(&self, depth: u64) -> u64
Perft (performance test) - counts leaf nodes at a given depth.
This is the standard metric for verifying move generation correctness. Each unique position at the target depth is counted exactly once.
§Example
use kish::Board;
let board = Board::new_default();
let nodes = board.perft(3);
println!("Positions at depth 3: {}", nodes);Sourcepub fn perft_parallel(&self, depth: u64, tt_size_mb: usize) -> u64
pub fn perft_parallel(&self, depth: u64, tt_size_mb: usize) -> u64
Parallel perft with transposition table for deep searches.
Uses rayon to parallelize at the top level and a lock-free transposition table to cache and reuse results for positions that occur via transposition.
§Arguments
depth- The search depthtt_size_mb- Approximate size of transposition table in megabytes (0 to disable)
§Example
use kish::Board;
let board = Board::new_default();
// Use 256MB transposition table
let nodes = board.perft_parallel(9, 256);
println!("Perft(9) = {}", nodes);Trait Implementations§
Source§impl Ord for Board
impl Ord for Board
Source§impl PartialOrd for Board
impl PartialOrd for Board
impl Copy for Board
impl Eq for Board
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 UnwindSafe for Board
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more