Struct shakmaty::bitboard::Bitboard[][src]

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.

👎 Deprecated since 0.20.4:

Renamed to Bitboard::from_rank()

Returns the bitboard containing all squares of the given file.

👎 Deprecated since 0.20.4:

Renamed to Bitboard::from_file()

👎 Deprecated since 0.20.4:

Use color.relative_rank()

Like rank(), but from the point of view of color.

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

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

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

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

An iterator over the subsets of this 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 . . .

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
👎 Deprecated since 0.20.1:

Renamed to Bitboard::FULL for consistency

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

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

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

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

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

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.