pub struct Bitboard(pub u64);
Expand description
Tuple Fields
0: u64
Implementations
sourceimpl Bitboard
impl Bitboard
sourcepub const fn from_square(sq: Square) -> Bitboard
pub const fn from_square(sq: Square) -> Bitboard
A bitboard with a single square.
sourcepub const fn from_rank(rank: Rank) -> Bitboard
pub const fn from_rank(rank: Rank) -> Bitboard
Returns the bitboard containing all squares of the given rank.
sourcepub const fn from_file(file: File) -> Bitboard
pub const fn from_file(file: File) -> Bitboard
Returns the bitboard containing all squares of the given file.
sourcepub fn relative_shift(self, color: Color, shift: u32) -> Bitboard
👎Deprecated: use Bitboard::shift() or manual shifts for clearer semantics
pub fn relative_shift(self, color: Color, shift: u32) -> Bitboard
use Bitboard::shift() or manual shifts for clearer semantics
Shift using <<
for White
and >>
for Black
.
Examples
use shakmaty::{Bitboard, Color};
let bitboard = Bitboard(0x1e22_2212_0e0a_1222);
assert_eq!(bitboard.relative_shift(Color::Black, 8), Bitboard(0x001e_2222_120e_0a12));
// . . . . . . . .
// . 1 1 1 1 . . .
// . 1 . . . 1 . .
// . 1 . . . 1 . .
// . 1 . . 1 . . .
// . 1 1 1 . . . .
// . 1 . 1 . . . .
// . 1 . . 1 . . .
sourcepub const fn shift(self, offset: i32) -> Bitboard
pub const fn shift(self, offset: i32) -> Bitboard
Silently overflowing bitwise shift with a signed offset, <<
for
positive values and >>
for negative values.
Examples
use shakmaty::Bitboard;
let bitboard = Bitboard(0x1e22_2212_0e0a_1222);
assert_eq!(bitboard.shift(-8), Bitboard(0x001e_2222_120e_0a12));
// . . . . . . . .
// . 1 1 1 1 . . .
// . 1 . . . 1 . .
// . 1 . . . 1 . .
// . 1 . . 1 . . .
// . 1 1 1 . . . .
// . 1 . 1 . . . .
// . 1 . . 1 . . .
assert_eq!(bitboard.shift(64), Bitboard(0));
assert_eq!(bitboard.shift(i32::MIN), Bitboard(0));
sourcepub fn remove(&mut self, sq: Square) -> bool
pub fn remove(&mut self, sq: Square) -> bool
Removes a square from the bitboard.
Returns true
if the square was in the set. Use
Bitboard::discard()
if you do not care about the return value.
Examples
use shakmaty::{Bitboard, Square};
let mut bitboard = Bitboard::FULL;
assert_eq!(bitboard.remove(Square::E4), true);
assert_eq!(bitboard.remove(Square::E4), false);
sourcepub fn with<T: Into<Bitboard>>(self, squares: T) -> Bitboard
pub fn with<T: Into<Bitboard>>(self, squares: T) -> Bitboard
Returns the union of self
and squares
. Equivalent to bitwise |
.
sourcepub fn without<T: Into<Bitboard>>(self, squares: T) -> Bitboard
pub fn without<T: Into<Bitboard>>(self, squares: T) -> Bitboard
Returns self
without squares
(set difference).
sourcepub fn toggled<T: Into<Bitboard>>(self, squares: T) -> Bitboard
pub fn toggled<T: Into<Bitboard>>(self, squares: T) -> Bitboard
Returns all squares that are in self
or squares
but not in both
(symmetric set difference). Equivalent to bitwise ^
.
sourcepub fn is_disjoint<T: Into<Bitboard>>(self, other: T) -> bool
pub fn is_disjoint<T: Into<Bitboard>>(self, other: T) -> bool
Tests if self
and other
are disjoint.
sourcepub fn is_subset<T: Into<Bitboard>>(self, other: T) -> bool
pub fn is_subset<T: Into<Bitboard>>(self, other: T) -> bool
Tests if self
is a subset of other
.
Examples
use shakmaty::Bitboard;
assert!(Bitboard::DARK_SQUARES.is_subset(Bitboard::FULL));
sourcepub fn is_superset<T: Into<Bitboard>>(self, other: T) -> bool
pub fn is_superset<T: Into<Bitboard>>(self, other: T) -> bool
Tests if self
is a superset of other
.
Examples
use shakmaty::Bitboard;
assert!(Bitboard::FULL.is_superset(Bitboard::LIGHT_SQUARES));
sourcepub fn discard_first(&mut self)
pub fn discard_first(&mut self)
Discards the first square.
sourcepub fn without_first(self) -> Bitboard
pub fn without_first(self) -> Bitboard
Returns self
without the first square.
sourcepub const fn count(self) -> usize
pub const fn count(self) -> usize
Returns the number of squares in self
.
Examples
use shakmaty::Bitboard;
assert_eq!(Bitboard::CORNERS.count(), 4);
sourcepub fn more_than_one(self) -> bool
pub fn more_than_one(self) -> bool
Tests if there is more than one square in self
.
sourcepub fn single_square(self) -> Option<Square>
pub fn single_square(self) -> Option<Square>
Gets the only square in the set, if there is exactly one.
Examples
use shakmaty::{Bitboard, Square, Rank};
assert_eq!(Bitboard::from(Square::H5).single_square(), Some(Square::H5));
assert_eq!(Bitboard::from(Rank::First).single_square(), None);
sourcepub fn carry_rippler(self) -> CarryRipplerⓘNotable traits for CarryRipplerimpl Iterator for CarryRippler type Item = Bitboard;
pub fn carry_rippler(self) -> CarryRipplerⓘNotable traits for CarryRipplerimpl Iterator for CarryRippler type Item = Bitboard;
An iterator over the subsets of this bitboard.
Examples
use shakmaty::Bitboard;
for subset in Bitboard::CENTER.carry_rippler() {
assert!(subset.is_subset(Bitboard::CENTER));
}
sourcepub const fn flip_vertical(self) -> Bitboard
pub const fn flip_vertical(self) -> Bitboard
Mirror the bitboard vertically.
Examples
use shakmaty::Bitboard;
let bitboard = Bitboard(0x1e22_2212_0e0a_1222);
assert_eq!(bitboard.flip_vertical(), Bitboard(0x2212_0a0e_1222_221e));
// . 1 . . . 1 . .
// . 1 . . 1 . . .
// . 1 . 1 . . . .
// . 1 1 1 . . . .
// . 1 . . 1 . . .
// . 1 . . . 1 . .
// . 1 . . . 1 . .
// . 1 1 1 1 . . .
sourcepub const fn flip_horizontal(self) -> Bitboard
pub const fn flip_horizontal(self) -> Bitboard
Mirror the bitboard horizontally.
Examples
use shakmaty::Bitboard;
let bitboard = Bitboard(0x1e22_2212_0e0a_1222);
assert_eq!(bitboard.flip_horizontal(), Bitboard(0x7844_4448_7050_4844));
// . . . 1 1 1 1 .
// . . 1 . . . 1 .
// . . 1 . . . 1 .
// . . . 1 . . 1 .
// . . . . 1 1 1 .
// . . . . 1 . 1 .
// . . . 1 . . 1 .
// . . 1 . . . 1 .
sourcepub const fn flip_diagonal(self) -> Bitboard
pub const fn flip_diagonal(self) -> Bitboard
Mirror the bitboard at the a1-h8 diagonal.
Examples
use shakmaty::Bitboard;
let bitboard = Bitboard(0x1e22_2212_0e0a_1222);
assert_eq!(bitboard.flip_diagonal(), Bitboard(0x0000_6192_8c88_ff00));
// . . . . . . . .
// . . . . . . . .
// 1 . . . . 1 1 .
// . 1 . . 1 . . 1
// . . 1 1 . . . 1
// . . . 1 . . . 1
// 1 1 1 1 1 1 1 1
// . . . . . . . .
sourcepub const fn flip_anti_diagonal(self) -> Bitboard
pub const fn flip_anti_diagonal(self) -> Bitboard
Mirror the bitboard at the h1-a8 diagonal.
Examples
use shakmaty::Bitboard;
let bitboard = Bitboard(0x1e22_2212_0e0a_1222);
assert_eq!(bitboard.flip_anti_diagonal(), Bitboard(0x00ff_1131_4986_0000));
// . . . . . . . .
// 1 1 1 1 1 1 1 1
// 1 . . . 1 . . .
// 1 . . . 1 1 . .
// 1 . . 1 . . 1 .
// . 1 1 . . . . 1
// . . . . . . . .
// . . . . . . . .
sourcepub const fn rotate_90(self) -> Bitboard
pub const fn rotate_90(self) -> Bitboard
Rotate the bitboard 90 degrees clockwise.
Examples
use shakmaty::Bitboard;
let bitboard = Bitboard(0x1e22_2212_0e0a_1222);
assert_eq!(bitboard.rotate_90(), Bitboard(0x00ff_888c_9261_0000));
// . . . . . . . .
// 1 1 1 1 1 1 1 1
// . . . 1 . . . 1
// . . 1 1 . . . 1
// . 1 . . 1 . . 1
// 1 . . . . 1 1 .
// . . . . . . . .
// . . . . . . . .
sourcepub const fn rotate_180(self) -> Bitboard
pub const fn rotate_180(self) -> Bitboard
Rotate the bitboard 180 degrees.
Examples
use shakmaty::Bitboard;
let bitboard = Bitboard(0x1e22_2212_0e0a_1222);
assert_eq!(bitboard.rotate_180(), Bitboard(0x4448_5070_4844_4478));
// . . 1 . . . 1 .
// . . . 1 . . 1 .
// . . . . 1 . 1 .
// . . . . 1 1 1 .
// . . . 1 . . 1 .
// . . 1 . . . 1 .
// . . 1 . . . 1 .
// . . . 1 1 1 1 .
sourcepub const fn rotate_270(self) -> Bitboard
pub const fn rotate_270(self) -> Bitboard
Rotate the bitboard 270 degrees clockwise.
Examples
use shakmaty::Bitboard;
let bitboard = Bitboard(0x1e22_2212_0e0a_1222);
assert_eq!(bitboard.rotate_270(), Bitboard(0x0000_8649_3111_ff00));
// . . . . . . . .
// . . . . . . . .
// . 1 1 . . . . 1
// 1 . . 1 . . 1 .
// 1 . . . 1 1 . .
// 1 . . . 1 . . .
// 1 1 1 1 1 1 1 1
// . . . . . . . .
sourcepub const EMPTY: Bitboard = _
pub const EMPTY: Bitboard = _
An empty bitboard.
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
sourcepub const FULL: Bitboard = _
pub const FULL: Bitboard = _
A bitboard containing all squares.
// 1 1 1 1 1 1 1 1
// 1 1 1 1 1 1 1 1
// 1 1 1 1 1 1 1 1
// 1 1 1 1 1 1 1 1
// 1 1 1 1 1 1 1 1
// 1 1 1 1 1 1 1 1
// 1 1 1 1 1 1 1 1
// 1 1 1 1 1 1 1 1
sourcepub const DARK_SQUARES: Bitboard = _
pub const DARK_SQUARES: Bitboard = _
All dark squares.
// . 1 . 1 . 1 . 1
// 1 . 1 . 1 . 1 .
// . 1 . 1 . 1 . 1
// 1 . 1 . 1 . 1 .
// . 1 . 1 . 1 . 1
// 1 . 1 . 1 . 1 .
// . 1 . 1 . 1 . 1
// 1 . 1 . 1 . 1 .
sourcepub const LIGHT_SQUARES: Bitboard = _
pub const LIGHT_SQUARES: Bitboard = _
All light squares.
// 1 . 1 . 1 . 1 .
// . 1 . 1 . 1 . 1
// 1 . 1 . 1 . 1 .
// . 1 . 1 . 1 . 1
// 1 . 1 . 1 . 1 .
// . 1 . 1 . 1 . 1
// 1 . 1 . 1 . 1 .
// . 1 . 1 . 1 . 1
sourcepub const CORNERS: Bitboard = _
pub const CORNERS: Bitboard = _
The four corner squares.
// 1 . . . . . . 1
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// 1 . . . . . . 1
sourcepub const BACKRANKS: Bitboard = _
pub const BACKRANKS: Bitboard = _
The backranks.
// 1 1 1 1 1 1 1 1
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// 1 1 1 1 1 1 1 1
sourcepub const CENTER: Bitboard = _
pub const CENTER: Bitboard = _
The four center squares.
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . 1 1 . . .
// . . . 1 1 . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
sourcepub const NORTH: Bitboard = _
pub const NORTH: Bitboard = _
The northern half of the board.
// 1 1 1 1 1 1 1 1
// 1 1 1 1 1 1 1 1
// 1 1 1 1 1 1 1 1
// 1 1 1 1 1 1 1 1
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
sourcepub const SOUTH: Bitboard = _
pub const SOUTH: Bitboard = _
The southern half of the board.
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// 1 1 1 1 1 1 1 1
// 1 1 1 1 1 1 1 1
// 1 1 1 1 1 1 1 1
// 1 1 1 1 1 1 1 1
Trait Implementations
sourceimpl<T> BitAndAssign<T> for Bitboard where
T: Into<Bitboard>,
impl<T> BitAndAssign<T> for Bitboard where
T: Into<Bitboard>,
sourcefn bitand_assign(&mut self, rhs: T)
fn bitand_assign(&mut self, rhs: T)
Performs the &=
operation. Read more
sourceimpl<T> BitOrAssign<T> for Bitboard where
T: Into<Bitboard>,
impl<T> BitOrAssign<T> for Bitboard where
T: Into<Bitboard>,
sourcefn bitor_assign(&mut self, rhs: T)
fn bitor_assign(&mut self, rhs: T)
Performs the |=
operation. Read more
sourceimpl<T> BitXorAssign<T> for Bitboard where
T: Into<Bitboard>,
impl<T> BitXorAssign<T> for Bitboard where
T: Into<Bitboard>,
sourcefn bitxor_assign(&mut self, rhs: T)
fn bitxor_assign(&mut self, rhs: T)
Performs the ^=
operation. Read more
sourceimpl Extend<Square> for Bitboard
impl Extend<Square> for Bitboard
sourcefn extend<T: IntoIterator<Item = Square>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Square>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl FromIterator<Square> for Bitboard
impl FromIterator<Square> for Bitboard
sourcefn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = Square>,
fn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = Square>,
Creates a value from an iterator. Read more
sourceimpl IntoIterator for Bitboard
impl IntoIterator for Bitboard
sourceimpl Ord for Bitboard
impl Ord for Bitboard
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialEq<Bitboard> for Bitboard
impl PartialEq<Bitboard> for Bitboard
sourceimpl PartialOrd<Bitboard> for Bitboard
impl PartialOrd<Bitboard> for Bitboard
sourcefn partial_cmp(&self, other: &Bitboard) -> Option<Ordering>
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 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Copy for Bitboard
impl Eq for Bitboard
impl StructuralEq for Bitboard
impl StructuralPartialEq for Bitboard
Auto Trait Implementations
impl RefUnwindSafe for Bitboard
impl Send for Bitboard
impl Sync for Bitboard
impl Unpin for Bitboard
impl UnwindSafe for Bitboard
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more