pub struct Bitboard(pub u64);
Expand description

A set of squares represented by a 64 bit integer mask.

Examples

use shakmaty::Bitboard;

let bitboard = Bitboard(0x1e22_2212_0e0a_1222);
// . 1 1 1 1 . . .
// . 1 . . . 1 . .
// . 1 . . . 1 . .
// . 1 . . 1 . . .
// . 1 1 1 . . . .
// . 1 . 1 . . . .
// . 1 . . 1 . . .
// . 1 . . . 1 . .

Tuple Fields

0: u64

Implementations

A bitboard with a single square.

Returns the bitboard containing all squares of the given rank.

Returns the bitboard containing all squares of the given file.

👎 Deprecated:

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

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));

Tests if self is non-empty.

Examples
use shakmaty::Bitboard;

assert!(Bitboard::BACKRANKS.any());

Tests if self is empty.

Examples
use shakmaty::Bitboard;

assert!(Bitboard::EMPTY.is_empty());

Tests if self contains the given square.

Adds squares.

Toggles squares.

Discards squares.

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);

Conditionally adds or discards square.

Clears all squares.

Returns the union of self and squares. Equivalent to bitwise |.

Returns self without squares (set difference).

Returns all squares that are in self or squares but not in both (symmetric set difference). Equivalent to bitwise ^.

Tests if self and other are disjoint.

Tests if self is a subset of other.

Examples
use shakmaty::Bitboard;

assert!(Bitboard::DARK_SQUARES.is_subset(Bitboard::FULL));

Tests if self is a superset of other.

Examples
use shakmaty::Bitboard;

assert!(Bitboard::FULL.is_superset(Bitboard::LIGHT_SQUARES));

Removes and returns the first square, if any.

Returns the first square, if any.

Discards the first square.

Returns self without the first square.

Removes and returns the last square, if any.

Returns the last square.

Returns the number of squares in self.

Examples
use shakmaty::Bitboard;

assert_eq!(Bitboard::CORNERS.count(), 4);

Tests if there is more than one square in self.

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);

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));
}

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

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 .

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
// . . . . . . . .

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
// . . . . . . . .
// . . . . . . . .

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 .
// . . . . . . . .
// . . . . . . . .

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 .

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
// . . . . . . . .

An empty 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

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 .

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

The four corner squares.

// 1 . . . . . . 1
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// 1 . . . . . . 1

The backranks.

// 1 1 1 1 1 1 1 1
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// 1 1 1 1 1 1 1 1

The four center squares.

// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . 1 1 . . .
// . . . 1 1 . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .

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
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .
// . . . . . . . .

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

The western 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 . . . .

The eastern 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

Formats the value using the given formatter.

The resulting type after applying the & operator.

Performs the & operation. Read more

Performs the &= operation. Read more

The resulting type after applying the | operator.

Performs the | operation. Read more

Performs the |= operation. Read more

The resulting type after applying the ^ operator.

Performs the ^ operation. Read more

Performs the ^= operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

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

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Creates a value from an iterator. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

Formats the value using the given formatter.

The resulting type after applying the ! operator.

Performs the unary ! operation. Read more

Formats the value using the given formatter.

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Formats the value using the given formatter.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.