Struct shakmaty::board::Board

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

Piece positions on a board.

Examples

use shakmaty::{Square, Board, Color::Black};

let board = Board::new();
// r n b q k b n r
// p p p p p p p p
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// P P P P P P P P
// R N B Q K B N R

assert_eq!(board.piece_at(Square::E8), Some(Black.king()));

Implementations§

source§

impl Board

source

pub const fn new() -> Board

source

pub const fn empty() -> Board

source

pub fn from_bitboards( by_role: ByRole<Bitboard>, by_color: ByColor<Bitboard> ) -> Board

Creates a board from bitboard constituents.

Panics

Panics if the bitboards are inconsistent.

source

pub const fn into_bitboards(self) -> (ByRole<Bitboard>, ByColor<Bitboard>)

source

pub const fn racing_kings() -> Board

Available on crate feature variant only.
source

pub const fn horde() -> Board

Available on crate feature variant only.
source

pub const fn occupied(&self) -> Bitboard

source

pub const fn pawns(&self) -> Bitboard

source

pub const fn knights(&self) -> Bitboard

source

pub const fn bishops(&self) -> Bitboard

source

pub const fn rooks(&self) -> Bitboard

source

pub const fn queens(&self) -> Bitboard

source

pub const fn kings(&self) -> Bitboard

source

pub const fn white(&self) -> Bitboard

source

pub const fn black(&self) -> Bitboard

source

pub const fn sliders(&self) -> Bitboard

Bishops, rooks and queens.

source

pub const fn steppers(&self) -> Bitboard

Pawns, knights and kings.

source

pub const fn rooks_and_queens(&self) -> Bitboard

source

pub const fn bishops_and_queens(&self) -> Bitboard

source

pub const fn king_of(&self, color: Color) -> Option<Square>

The (unique!) king of the given side, if any.

source

pub fn color_at(&self, sq: Square) -> Option<Color>

source

pub fn role_at(&self, sq: Square) -> Option<Role>

source

pub fn piece_at(&self, sq: Square) -> Option<Piece>

source

pub fn remove_piece_at(&mut self, sq: Square) -> Option<Piece>

source

pub fn discard_piece_at(&mut self, sq: Square)

source

pub fn set_piece_at(&mut self, sq: Square, _: Piece)

source

pub const fn by_color(&self, color: Color) -> Bitboard

source

pub const fn by_role(&self, role: Role) -> Bitboard

source

pub const fn by_piece(&self, piece: Piece) -> Bitboard

source

pub fn attacks_from(&self, sq: Square) -> Bitboard

source

pub fn attacks_to( &self, sq: Square, attacker: Color, occupied: Bitboard ) -> Bitboard

source

pub fn material_side(&self, color: Color) -> ByRole<u8>

source

pub fn material(&self) -> ByColor<ByRole<u8>>

source

pub fn flip_vertical(&mut self)

Mirror the board vertically. See Bitboard::flip_vertical.

source

pub fn flip_horizontal(&mut self)

Mirror the board horizontally. See Bitboard::flip_horizontal.

source

pub fn flip_diagonal(&mut self)

Mirror the board at the a1-h8 diagonal. See Bitboard::flip_diagonal.

source

pub fn flip_anti_diagonal(&mut self)

Mirror the board at the h1-a8 diagonal. See Bitboard::flip_anti_diagonal.

source

pub fn rotate_90(&mut self)

Rotate the board 90 degrees clockwise. See Bitboard::rotate_90.

source

pub fn rotate_180(&mut self)

Rotate the board 180 degrees. See Bitboard::rotate_180.

source

pub fn rotate_270(&mut self)

Rotate the board 270 degrees clockwise. See Bitboard::rotate_270.

source

pub fn pop_front(&mut self) -> Option<(Square, Piece)>

source

pub fn pop_back(&mut self) -> Option<(Square, Piece)>

source§

impl Board

source

pub fn from_ascii_board_fen(board_fen: &[u8]) -> Result<Board, ParseFenError>

source

pub const fn board_fen(&self, promoted: Bitboard) -> BoardFen<'_>

Create a board FEN such as rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR.

Promoted pieces are marked like Q~.

Returns a BoardFen which implements Display.

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 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 Extend<(Square, Piece)> for Board

source§

fn extend<T: IntoIterator<Item = (Square, Piece)>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl FromIterator<(Square, Piece)> for Board

source§

fn from_iter<T>(iter: T) -> Boardwhere T: IntoIterator<Item = (Square, Piece)>,

Creates a value from an iterator. Read more
source§

impl FromStr for Board

§

type Err = ParseFenError

The associated error which can be returned from parsing.
source§

fn from_str(board_fen: &str) -> Result<Board, ParseFenError>

Parses a string s to return a value of this type. Read more
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 IntoIterator for Board

§

type IntoIter = IntoIter

Which kind of iterator are we turning this into?
§

type Item = (Square, Piece)

The type of the elements being iterated over.
source§

fn into_iter(self) -> IntoIter

Creates an iterator from a value. Read more
source§

impl PartialEq<Board> for Board

source§

fn eq(&self, other: &Board) -> 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 Board

source§

impl StructuralEq for Board

source§

impl StructuralPartialEq for Board

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere 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 Twhere 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.