Struct cozy_chess::BoardBuilder
source · 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
impl BoardBuilder
sourcepub fn empty() -> Self
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());
}
sourcepub fn startpos() -> Self
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);
sourcepub fn chess960_startpos(scharnagl_number: u32) -> Self
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);
sourcepub fn double_chess960_startpos(
white_scharnagl_number: u32,
black_scharnagl_number: u32
) -> Self
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);
sourcepub fn from_board(board: &Board) -> Self
pub fn from_board(board: &Board) -> Self
sourcepub fn square(&self, square: Square) -> Option<(Piece, Color)>
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)));
sourcepub fn square_mut(&mut self, square: Square) -> &mut Option<(Piece, Color)>
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)));
sourcepub fn castle_rights(&self, color: Color) -> &CastleRights
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));
sourcepub fn castle_rights_mut(&mut self, color: Color) -> &mut CastleRights
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);
Trait Implementations§
source§impl Clone for BoardBuilder
impl Clone for BoardBuilder
source§fn clone(&self) -> BoardBuilder
fn clone(&self) -> BoardBuilder
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for BoardBuilder
impl Debug for BoardBuilder
source§impl Default for BoardBuilder
impl Default for BoardBuilder
source§impl Hash for BoardBuilder
impl Hash for BoardBuilder
source§impl PartialEq for BoardBuilder
impl PartialEq for BoardBuilder
source§fn eq(&self, other: &BoardBuilder) -> bool
fn eq(&self, other: &BoardBuilder) -> bool
self
and other
values to be equal, and is used
by ==
.