Struct PieceSets

Source
pub struct PieceSets { /* private fields */ }
Expand description

A Piece-Centric representation of pieces on a chessboard. A Bitboard is used to encode the squares of each chess piece. PieceSets indexes by piece to get squares, as opposed to Mailbox which indexes by square to get a piece.

Implementations§

Source§

impl PieceSets

Source

pub fn new() -> Self

Returns PieceSets with all Bitboards set to empty.

Source

pub fn start_position() -> Self

Returns PieceSets arranged in starting chess position.

Source

pub fn occupied(&self) -> Bitboard

Return a bitboard representing the set of squares occupied by any piece. Note: Compiler can auto-vectorize, however looking at assembly on godbolt may be limited to avx128. Does not seem to use avx512 on supported cpus.

Source

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

Return a bitboard representing the set of squares occupied by piece of color.

Source

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

Finds and returns the first piece found on target square, or None.

Source

pub fn on_player_square(&self, player: Color, sq: Square) -> Option<PieceKind>

Finds and returns the first PieceKind found on target square of player’s pieces, or None.

Source

pub fn pretty(&self) -> String

Returns pretty-printed chess board representation of Self. Uses Mailbox pretty.

Source

pub fn is_disjoint(&self) -> bool

Returns true if all sets in self are disjoint (mutually exclusive). In other words, there is no more than 1 piece per square. If a square is in one set, it is in no other. PieceSets should be disjoint at all times.

Source

pub fn is_valid(&self) -> bool

Returns true if Self is valid. A valid PieceSets has the following properties:

  • Has a single king per side.
  • Each bitboard is disjoint (mutually exclusive) meaning a square cannot have more than one piece.

Trait Implementations§

Source§

impl Clone for PieceSets

Source§

fn clone(&self) -> PieceSets

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 PieceSets

Source§

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

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

impl Default for PieceSets

Defaults to standard chess piece starting positions.

Source§

fn default() -> Self

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

impl Display for PieceSets

Source§

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

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

impl FenComponent for PieceSets

Placement FenComponent.

Source§

impl From<&Mailbox> for PieceSets

Source§

fn from(mb: &Mailbox) -> Self

Converts to this type from the input type.
Source§

impl From<&PieceSets> for Mailbox

Source§

fn from(pieces: &PieceSets) -> Mailbox

Converts to this type from the input type.
Source§

impl Index<&(Color, PieceKind)> for PieceSets

Source§

type Output = Bitboard

The returned type after indexing.
Source§

fn index(&self, (color, piece_kind): &(Color, PieceKind)) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<&Piece> for PieceSets

Source§

type Output = Bitboard

The returned type after indexing.
Source§

fn index(&self, piece: &Piece) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<(Color, PieceKind)> for PieceSets

Source§

type Output = Bitboard

The returned type after indexing.
Source§

fn index(&self, (color, piece_kind): (Color, PieceKind)) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<Color> for PieceSets

Get a slice of all pieces of same color.

let ps = PieceSets::start_position();
let w_slice = &ps[Color::White];
let b_slice = &ps[Color::Black];
assert_eq!(b_slice.len(), w_slice.len());
assert_eq!(b_slice.len(), 6);
Source§

type Output = [Bitboard]

The returned type after indexing.
Source§

fn index(&self, color: Color) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<Piece> for PieceSets

Source§

type Output = Bitboard

The returned type after indexing.
Source§

fn index(&self, piece: Piece) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<&(Color, PieceKind)> for PieceSets

Source§

fn index_mut( &mut self, (color, piece_kind): &(Color, PieceKind), ) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<&Piece> for PieceSets

Source§

fn index_mut(&mut self, piece: &Piece) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<(Color, PieceKind)> for PieceSets

Source§

fn index_mut( &mut self, (color, piece_kind): (Color, PieceKind), ) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<Color> for PieceSets

Source§

fn index_mut(&mut self, color: Color) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<Piece> for PieceSets

Source§

fn index_mut(&mut self, piece: Piece) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl PartialEq for PieceSets

Source§

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

Source§

impl Eq for PieceSets

Source§

impl StructuralPartialEq for PieceSets

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V