Struct chess::Board

source ·
pub struct Board { /* private fields */ }
Expand description

A representation of a chess board. That’s why you’re here, right?

Implementations§

source§

impl Board

source

pub fn new() -> Board

Construct a new Board that is completely empty. Note: This does NOT give you the initial position. Just a blank slate.

source

pub fn from_fen(fen: String) -> Option<Board>

Construct a board from a FEN string.

source

pub fn status(&self) -> BoardStatus

Is this game Ongoing, is it Stalemate, or is it Checkmate?

source

pub fn combined(&self) -> BitBoard

Grab the “combined” BitBoard. This is a BitBoard with every piece

source

pub fn color_combined(&self, color: Color) -> BitBoard

Grab the “color combined” BitBoard. This is a BitBoard with every piece of a particular color.

source

pub fn king_square(&self, color: Color) -> Square

Give me the Square the color king is on.

source

pub fn pieces(&self, piece: Piece) -> BitBoard

Grab the “pieces” BitBoard. This is a BitBoard with every piece of a particular type.

source

pub fn castle_rights(&self, color: Color) -> CastleRights

Grab the CastleRights for a particular side.

source

pub fn add_castle_rights(&mut self, color: Color, add: CastleRights)

Add castle rights for a particular side.

source

pub fn remove_castle_rights(&mut self, color: Color, remove: CastleRights)

Remove castle rights for a particular side.

source

pub fn side_to_move(&self) -> Color

Who’s turn is it?

source

pub fn my_castle_rights(&self) -> CastleRights

Grab my CastleRights.

source

pub fn add_my_castle_rights(&mut self, add: CastleRights)

Add to my CastleRights.

source

pub fn remove_my_castle_rights(&mut self, remove: CastleRights)

Remove some of my CastleRights.

source

pub fn their_castle_rights(&self) -> CastleRights

My opponents CastleRights.

source

pub fn add_their_castle_rights(&mut self, add: CastleRights)

Ad to my opponents CastleRights

source

pub fn remove_their_castle_rights(&mut self, remove: CastleRights)

Remove some of my opponents CastleRights.

source

pub fn set_piece( &self, piece: Piece, color: Color, square: Square, ) -> Option<Board>

For a chess UI: set a piece on a particular square

source

pub fn clear_square(&self, square: Square) -> Option<Board>

For a chess UI: clear a particular square

source

pub fn null_move(&self) -> Option<Board>

Switch the color of the player without actually making a move

source

pub fn is_sane(&self) -> bool

Does this board “make sense”? Do all the pieces make sense, do the bitboards combine correctly, etc? This is for sanity checking.

source

pub fn get_hash(&self) -> u64

Get a hash of the board

source

pub fn get_pawn_hash(&self) -> u64

Get a pawn hash of the board (a hash that only changes on color change and pawn moves)

source

pub fn piece_on(&self, square: Square) -> Option<Piece>

What piece is on a particular Square? Is there even one?

source

pub fn enumerate_moves(&self, moves: &mut [ChessMove; 256]) -> usize

Give me all the legal moves for this board.

Note: You may want to build a MoveGen structure to iterate over the moves instead.

source

pub fn en_passant(self) -> Option<Square>

Give me the en_passant square, if it exists

source

pub fn legal(&self, m: ChessMove) -> bool

Is a particular move legal?

source

pub fn make_move(&self, m: ChessMove) -> Board

Make a chess move

source

pub fn perft(&self, depth: u64) -> u64

Run a perft-test.

source

pub fn perft_brute_force(&self, depth: u64) -> u64

Run a perft-test using brute force move generation

source

pub fn perft_cache(&self, depth: u64, cache_size_per_depth: usize) -> u64

Run a perft test with a cache table

source

pub fn pinned(&self) -> BitBoard

source

pub fn checkers(&self) -> BitBoard

source

pub fn legal_king_move(&self, dest: Square) -> bool

Is a particular king move legal?

source

pub fn legal_ep_move(&self, source: Square, dest: Square) -> bool

Is a particular en-passant capture legal?

source

pub fn perft_test(fen: String, depth: u64, result: u64)

Run every type of perft test, and panic! if the leaf-node count of any version is not equal to result.

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 Display for Board

source§

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

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

impl Copy 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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

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