pub struct BoardBuilder {
    pub board: [Option<(Piece, Color)>; 64],
    pub side_to_move: Color,
    pub castle_rights: [CastleRights; 2],
    pub en_passant: Option<Square>,
    pub halfmove_clock: u8,
    pub fullmove_number: u16,
}
Expand description

A board builder to manipulate arbitrary boards.

Fields§

§board: [Option<(Piece, Color)>; 64]

The board state. Index by square to get the corresponding piece.

§side_to_move: Color

The side to move.

§castle_rights: [CastleRights; 2]

The castling rights. Index by color to get the corresponding side’s rights.

§en_passant: Option<Square>

The en passant square.

§halfmove_clock: u8

The halfmove clock.

§fullmove_number: u16

The fullmove number.

Implementations§

source§

impl BoardBuilder

source

pub fn empty() -> Self

Get an empty builder. All fields are set to their empty values.

§Examples
let builder = BoardBuilder::empty();
for &square in &Square::ALL {
    assert!(builder.square(square).is_none());
}
source

pub fn startpos() -> Self

Get a builder set to the default start position.

§Examples
let startpos = Board::default();
let builder = BoardBuilder::default();
assert_eq!(builder.build().unwrap(), startpos);
source

pub fn chess960_startpos(scharnagl_number: u32) -> Self

Get a builder set to a chess960 start position. Converts a scharnagl number to its corresponding position.

§Panics

Panic if the scharnagl number is invalid (not within the range 0..960).

§Examples
let startpos = Board::default();
// 518 is the scharnagl number for the default start position.
let builder = BoardBuilder::chess960_startpos(518);
assert_eq!(builder.build().unwrap(), startpos);
source

pub fn double_chess960_startpos( white_scharnagl_number: u32, black_scharnagl_number: u32 ) -> Self

Get a builder set to a double chess960 start position. Uses two scharnagl numbers for the initial setup for white and the initial setup for black.

§Panics

Panic if either scharnagl number is invalid (not within the range 0..960).

§Examples
let startpos = Board::default();
// 518 is the scharnagl number for the default start position.
let builder = BoardBuilder::double_chess960_startpos(518, 518);
assert_eq!(builder.build().unwrap(), startpos);
source

pub fn from_board(board: &Board) -> Self

Create a builder from a Board.

§Examples
let board = Board::default();
let builder = BoardBuilder::from_board(&board);
assert_eq!(builder.build().unwrap(), board);
source

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

Get a square on the board.

§Examples
let builder = BoardBuilder::default();
assert_eq!(builder.square(Square::A1), Some((Piece::Rook, Color::White)));
source

pub fn square_mut(&mut self, square: Square) -> &mut Option<(Piece, Color)>

Mutably get a square on the board.

§Examples
let mut builder = BoardBuilder::default();
*builder.square_mut(Square::A1) = Some((Piece::Knight, Color::White));
assert_eq!(builder.square(Square::A1), Some((Piece::Knight, Color::White)));
source

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

Get the castle rights for a side.

§Examples
let builder = BoardBuilder::default();
let rights = builder.castle_rights(Color::White);
assert_eq!(rights.short, Some(File::H));
assert_eq!(rights.long, Some(File::A));
source

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

Mutably get the castle rights for a side.

§Examples
let mut builder = BoardBuilder::default();
let rights = builder.castle_rights_mut(Color::White);
rights.short = None;
assert_eq!(rights.short, None);
source

pub fn build(&self) -> Result<Board, BoardBuilderError>

Build a Board from this builder.

§Errors

This will error if the current state is invalid.

§Examples
let builder = BoardBuilder::default().build().unwrap();
assert_eq!(builder, Board::default());

Trait Implementations§

source§

impl Clone for BoardBuilder

source§

fn clone(&self) -> BoardBuilder

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 Debug for BoardBuilder

source§

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

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

impl Default for BoardBuilder

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Hash for BoardBuilder

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 PartialEq for BoardBuilder

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for BoardBuilder

source§

impl StructuralPartialEq for BoardBuilder

Auto Trait Implementations§

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