Board

Struct Board 

Source
pub struct Board {
    pub turn: Team,
    pub state: State,
}
Expand description

The main game board combining piece positions and current turn.

Fields§

§turn: Team

The current team’s turn.

§state: State

The state of the board.

Implementations§

Source§

impl Board

Source

pub fn actions(&self) -> Vec<Action>

Computes the valid actions of the board.

Source

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.

Source

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

Source

pub const fn new(turn: Team, state: State) -> Self

Creates a new board.

Source

pub const fn new_default() -> Self

Creates a new board with default configuration.

Source

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.

Source

pub const fn friendly_pieces(&self) -> u64

Returns the friendly pieces.

Source

pub const fn hostile_pieces(&self) -> u64

Returns the hostile pieces.

Source

pub const fn swap_turn_(&mut self)

Swaps the player’s turn in-place.

Source

pub fn swap_turn(&self) -> Self

Swaps the player’s turn and returns the new board.

Source

pub fn apply_(&mut self, action: &Action)

Applies the given action to the board in-place.

Source

pub fn apply(&self, action: &Action) -> Self

Applies the given action to the board and returns the new board.

Source

pub fn rotate_(&mut self)

Rotates the board by 180 degrees in-place.

Source

pub fn rotate(&self) -> Self

Rotates the board by 180 degrees and returns the new board.

Source

pub fn status(&self) -> GameStatus

Computes the status of the board.

Source§

impl Board

Source

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);
Source

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 depth
  • tt_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 Clone for Board

Source§

fn clone(&self) -> Board

Returns a duplicate 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 Debug for Board

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Board

Source§

fn default() -> Board

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
Source§

impl From<Board> for Game

Source§

fn from(board: Board) -> Self

Converts to this type from the input type.
Source§

impl Hash for Board

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Board

Source§

fn cmp(&self, other: &Board) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Board

Source§

fn eq(&self, other: &Board) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Board

Source§

fn partial_cmp(&self, other: &Board) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Board

Source§

impl Eq for Board

Source§

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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§

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

Source§

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

Source§

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.