pub struct Bitboard(pub u64);
Expand description
Tuple Fields§
§0: u64
Implementations§
source§impl 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 const fn relative_shift(self, color: Color, shift: u32) -> Bitboard
👎Deprecated: use Bitboard::shift() or manual shifts for clearer semantics
pub const fn relative_shift(self, color: Color, shift: u32) -> Bitboard
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 const fn intersect(self, squares: Bitboard) -> Bitboard
pub const fn intersect(self, squares: Bitboard) -> Bitboard
Returns the intersection of self
and squares
. Equivalent to bitwise &
.
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 const fn with_const(self, squares: Bitboard) -> Bitboard
pub const fn with_const(self, squares: Bitboard) -> Bitboard
Same as the with
method, but usable in const
contexts.
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 const fn without_const(self, squares: Bitboard) -> Bitboard
pub const fn without_const(self, squares: Bitboard) -> Bitboard
Same as the without
method, but usable in const
contexts.
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 const fn toggled_const(self, squares: Bitboard) -> Bitboard
pub const fn toggled_const(self, squares: Bitboard) -> Bitboard
Same as the toggled
method, but usable in const
contexts.
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 const fn is_disjoint_const(self, other: Bitboard) -> bool
pub const fn is_disjoint_const(self, other: Bitboard) -> bool
Same as the is_disjoint
method, but usable in const
contexts.
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 const fn is_subset_const(self, other: Bitboard) -> bool
pub const fn is_subset_const(self, other: Bitboard) -> bool
Same as the is_subset
method, but usable in const
contexts.
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 const fn is_superset_const(self, other: Bitboard) -> bool
pub const fn is_superset_const(self, other: Bitboard) -> bool
Same as the is_superset
method, but usable in const
contexts.
sourcepub fn discard_first(&mut self)
pub fn discard_first(&mut self)
Discards the first square.
sourcepub const fn without_first(self) -> Bitboard
pub const 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 const fn more_than_one(self) -> bool
pub const fn more_than_one(self) -> bool
Tests if there is more than one square in self
.
sourcepub const fn single_square(self) -> Option<Square>
pub const 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 const fn carry_rippler(self) -> CarryRippler ⓘ
pub const fn carry_rippler(self) -> CarryRippler ⓘ
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§
source§impl<T> BitAndAssign<T> for Bitboardwhere
T: Into<Bitboard>,
impl<T> BitAndAssign<T> for Bitboardwhere
T: Into<Bitboard>,
source§fn bitand_assign(&mut self, rhs: T)
fn bitand_assign(&mut self, rhs: T)
&=
operation. Read moresource§impl<T> BitOrAssign<T> for Bitboardwhere
T: Into<Bitboard>,
impl<T> BitOrAssign<T> for Bitboardwhere
T: Into<Bitboard>,
source§fn bitor_assign(&mut self, rhs: T)
fn bitor_assign(&mut self, rhs: T)
|=
operation. Read moresource§impl<T> BitXorAssign<T> for Bitboardwhere
T: Into<Bitboard>,
impl<T> BitXorAssign<T> for Bitboardwhere
T: Into<Bitboard>,
source§fn bitxor_assign(&mut self, rhs: T)
fn bitxor_assign(&mut self, rhs: T)
^=
operation. Read moresource§impl Extend<Square> for Bitboard
impl Extend<Square> for Bitboard
source§fn extend<T: IntoIterator<Item = Square>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Square>>(&mut self, iter: T)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl FromIterator<Square> for Bitboard
impl FromIterator<Square> for Bitboard
source§impl IntoIterator for Bitboard
impl IntoIterator for Bitboard
source§impl Ord for Bitboard
impl Ord for Bitboard
source§impl PartialOrd<Bitboard> for Bitboard
impl PartialOrd<Bitboard> for Bitboard
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more