Struct BitBoard

Source
pub struct BitBoard(pub u64);
Expand description

A bitboard is a value type wrapping a 64 bit integer which represents a set of squares on a chess board. Each bit is mapped to a particular square on the board, 0 -> H1, 1 -> G1,…, 8 -> H2,…, 63 -> A8. For example if we know a piece to reside on a particular square we can use a bitboard to to capture the available moves for that piece.

Tuple Fields§

§0: u64

Implementations§

Source§

impl BitBoard

Source

pub const EMPTY: BitBoard

The empty bitboard (set of no squares).

Source

pub const ALL: BitBoard

The complete bitboard (set of all squares).

Source

pub const RANKS: [BitBoard; 8]

Array of bitboards represented the eight ranks, ordered 1 to 8.

Source

pub const FILES: [BitBoard; 8]

Array of bitboards represented the eight files, ordered H to A.

Source

pub fn contains(self, square: Square) -> bool

Check if this bitboard contains a particular square.

Source

pub fn subsumes(self, other: BitBoard) -> bool

Check if this set is a superset of the other.

Source

pub fn is_empty(self) -> bool

Check if this bitboard is empty, i.e contains no squares.

Source

pub fn is_populated(self) -> bool

Check if this bitboard contains at least one square.

Source

pub fn intersects(self, other: BitBoard) -> bool

Check if the intersection of this bitboard and the other is non-empty.

Source

pub fn size(self) -> usize

Computes the number of squares in this bitboard using the popcount algorithm.

Source

pub fn iter(self) -> impl Iterator<Item = Square>

Source

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

Finds the first square in this set if it is non-empty.

Source

pub fn least_set_bit(self) -> BitBoard

Returns a bitboard with the least set bit of this bitboard or nothing if this bitboard is empty.

Source

pub fn cord(source: Square, target: Square) -> BitBoard

Computes the ‘cord’ between two squares. Imagine a queen sat on the source square on and empty board. If the queen can move to the target square then this method returns the set of squares which the queen slides along to get to this target square (inclusive of both ends) otherwise the empty bitboard is returned.

Trait Implementations§

Source§

impl BitAnd<BitBoard> for Square

Source§

type Output = BitBoard

The resulting type after applying the & operator.
Source§

fn bitand(self, other: BitBoard) -> Self::Output

Performs the & operation. Read more
Source§

impl BitAnd<Square> for BitBoard

Source§

type Output = BitBoard

The resulting type after applying the & operator.
Source§

fn bitand(self, other: Square) -> Self

Performs the & operation. Read more
Source§

impl BitAnd for BitBoard

Source§

type Output = BitBoard

The resulting type after applying the & operator.
Source§

fn bitand(self, other: BitBoard) -> Self

Performs the & operation. Read more
Source§

impl BitOr<BitBoard> for Square

Source§

type Output = BitBoard

The resulting type after applying the | operator.
Source§

fn bitor(self, other: BitBoard) -> Self::Output

Performs the | operation. Read more
Source§

impl BitOr<Square> for BitBoard

Source§

type Output = BitBoard

The resulting type after applying the | operator.
Source§

fn bitor(self, other: Square) -> Self

Performs the | operation. Read more
Source§

impl BitOr for BitBoard

Source§

type Output = BitBoard

The resulting type after applying the | operator.
Source§

fn bitor(self, other: BitBoard) -> Self

Performs the | operation. Read more
Source§

impl BitOrAssign<Square> for BitBoard

Source§

fn bitor_assign(&mut self, rhs: Square)

Performs the |= operation. Read more
Source§

impl BitOrAssign for BitBoard

Source§

fn bitor_assign(&mut self, rhs: BitBoard)

Performs the |= operation. Read more
Source§

impl BitXor<Square> for BitBoard

Source§

type Output = BitBoard

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Square) -> Self

Performs the ^ operation. Read more
Source§

impl BitXor for BitBoard

Source§

type Output = BitBoard

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, other: BitBoard) -> Self

Performs the ^ operation. Read more
Source§

impl BitXorAssign<Square> for BitBoard

Source§

fn bitxor_assign(&mut self, rhs: Square)

Performs the ^= operation. Read more
Source§

impl BitXorAssign for BitBoard

Source§

fn bitxor_assign(&mut self, rhs: BitBoard)

Performs the ^= operation. Read more
Source§

impl Clone for BitBoard

Source§

fn clone(&self) -> BitBoard

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 BitBoard

Source§

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

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

impl Display for BitBoard

Source§

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

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

impl FromIterator<BitBoard> for BitBoard

We can collect an iterator of bitboards into a single bitboard under the logical OR binary operator on sets.

Source§

fn from_iter<I: IntoIterator<Item = BitBoard>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<Square> for BitBoard

A set of squares can be built from an iterator traversing squares.

Source§

fn from_iter<I: IntoIterator<Item = Square>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Hash for BitBoard

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 BitBoard

A bitboard is a set of squares and is therefore iterable.

Source§

type Item = Square

The type of the elements being iterated over.
Source§

type IntoIter = BitBoardIterator

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Not for BitBoard

Source§

type Output = BitBoard

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self

Performs the unary ! operation. Read more
Source§

impl Ord for BitBoard

Source§

fn cmp(&self, other: &BitBoard) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for BitBoard

Source§

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

Source§

fn partial_cmp(&self, other: &BitBoard) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Reflectable for BitBoard

Source§

fn reflect(&self) -> Self

Source§

impl Shl<u8> for BitBoard

Source§

type Output = BitBoard

The resulting type after applying the << operator.
Source§

fn shl(self, shift: u8) -> Self

Performs the << operation. Read more
Source§

impl Shr<u8> for BitBoard

Operator implementations for bitboards which all use the underlying u64 value.

Source§

type Output = BitBoard

The resulting type after applying the >> operator.
Source§

fn shr(self, shift: u8) -> Self

Performs the >> operation. Read more
Source§

impl Sub<BitBoard> for Square

Source§

type Output = BitBoard

The resulting type after applying the - operator.
Source§

fn sub(self, other: BitBoard) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<Square> for BitBoard

Source§

type Output = BitBoard

The resulting type after applying the - operator.
Source§

fn sub(self, other: Square) -> Self

Performs the - operation. Read more
Source§

impl Sub for BitBoard

Source§

type Output = BitBoard

The resulting type after applying the - operator.
Source§

fn sub(self, other: BitBoard) -> Self

Performs the - operation. Read more
Source§

impl Copy for BitBoard

Source§

impl Eq for BitBoard

Source§

impl StructuralPartialEq for BitBoard

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.