pub struct Bitboard(/* private fields */);Expand description
A 64-bit Bitboard.
Implementations§
Source§impl Bitboard
impl Bitboard
Sourcepub const fn full() -> Self
pub const fn full() -> Self
Create a full Bitboard.
§Example
let full = Bitboard::full();
assert_eq!(full, Bitboard::new(0b1111111111111111111111111111111111111111111111111111111111111111));Sourcepub const fn empty() -> Self
pub const fn empty() -> Self
Create an empty Bitboard.
§Example
let empty = Bitboard::empty();
assert_eq!(empty, Bitboard::new(0b0000000000000000000000000000000000000000000000000000000000000000));Sourcepub fn with_one(pos: Position) -> Self
pub fn with_one(pos: Position) -> Self
Create a Bitboard with pos set to 1.
§Example
let bb = Bitboard::with_one(A7);
assert_eq!(bb, Bitboard::new(0b1000000000000000000000000000000000000000000000000));
// ABCDEFGH
// 8 00000000
// 7 10000000
// 6 00000000
// 5 00000000
// 4 00000000
// 3 00000000
// 2 00000000
// 1 00000000Sourcepub fn with_ones(positions: impl IntoIterator<Item = Position>) -> Self
pub fn with_ones(positions: impl IntoIterator<Item = Position>) -> Self
Create a Bitboard with all positions in positions set to 1.
§Example
let bb = Bitboard::with_ones([A1, B2, C3, D4, E5, F6, G7, H8]);
assert_eq!(bb, Bitboard::new(0b1000000001000000001000000001000000001000000001000000001000000001));
// ABCDEFGH
// 8 00000001
// 7 00000010
// 6 00000100
// 5 00001000
// 4 00010000
// 3 00100000
// 2 01000000
// 1 10000000Sourcepub fn bit_at(&self, pos: Position) -> bool
pub fn bit_at(&self, pos: Position) -> bool
Returns true if the bit at pos is 1, false otherwise.
§Example
let bb = Bitboard::with_one(F2);
assert!(bb.bit_at(F2));
assert!(!bb.bit_at(F3));Sourcepub fn include_position(self, pos: Position) -> Self
pub fn include_position(self, pos: Position) -> Self
Apply a mask to self, only including the bit at pos.
§Example
let bb = Bitboard::with_ones([F2, F3]);
let masked = bb.include_position(F3);
assert_eq!(masked, Bitboard::with_one(F3)); // the bit at F2 is now 0
// ABCDEFGH ABCDEFGH
// 8 00000000 8 00000000
// 7 00000000 7 00000000
// 6 00000000 6 00000000
// 5 00000000 -> 5 00000000
// 4 00000000 4 00000000
// 3 00000100 3 00000100
// 2 00000100 2 00000000
// 1 00000000 1 00000000Sourcepub fn include_positions(
self,
positions: impl IntoIterator<Item = Position>,
) -> Self
pub fn include_positions( self, positions: impl IntoIterator<Item = Position>, ) -> Self
Apply a mask to self, only including the bits at the given positions.
§Example
let bb = Bitboard::with_ones([F2, F3, F4]);
let masked = bb.include_positions([F3, F4, F5]);
assert_eq!(masked, Bitboard::with_ones([F3, F4])); // neither F2 nor F5 are in the resulting bitboard
// ABCDEFGH ABCDEFGH
// 8 00000000 8 00000000
// 7 00000000 7 00000000
// 6 00000000 6 00000000
// 5 00000000 -> 5 00000000
// 4 00000100 4 00000100
// 3 00000100 3 00000100
// 2 00000100 2 00000000
// 1 00000000 1 00000000Sourcepub fn clear_position(self, pos: Position) -> Self
pub fn clear_position(self, pos: Position) -> Self
Apply a mask to self, clearing the bit at position pos.
§Example
let bb = Bitboard::with_ones([F4, F5]);
let cleared = bb.clear_position(F4);
assert_eq!(cleared, Bitboard::with_one(F5)); // F4 has been cleared
// ABCDEFGH ABCDEFGH
// 8 00000000 8 00000000
// 7 00000000 7 00000000
// 6 00000000 6 00000000
// 5 00000100 -> 5 00000100
// 4 00000100 4 00000000
// 3 00000000 3 00000000
// 2 00000000 2 00000000
// 1 00000000 1 00000000Sourcepub fn clear_positions(
self,
positions: impl IntoIterator<Item = Position>,
) -> Self
pub fn clear_positions( self, positions: impl IntoIterator<Item = Position>, ) -> Self
Apply a mask to self, clearing the bit at each position in positions.
§Example
let bb = Bitboard::with_ones([F2, F3, F4]);
let cleared = bb.clear_positions([F2, F3]);
assert_eq!(cleared, Bitboard::with_one(F4)); // only F4 remains after clearing F2 and F3
// ABCDEFGH ABCDEFGH
// 8 00000000 8 00000000
// 7 00000000 7 00000000
// 6 00000000 6 00000000
// 5 00000000 -> 5 00000000
// 4 00000100 4 00000100
// 3 00000100 3 00000000
// 2 00000100 2 00000000
// 1 00000000 1 00000000Sourcepub fn include_file(self, file: File) -> Self
pub fn include_file(self, file: File) -> Self
Apply a mask to self, only including the bits at positions in the given file.
§Example
let bb = Bitboard::with_ones([A1, B1, C1]);
let masked = bb.include_file(File::A);
assert_eq!(masked, Bitboard::with_one(A1)); // B1 and C1 are not in file A
// ABCDEFGH ABCDEFGH
// 8 00000000 8 00000000
// 7 00000000 7 00000000
// 6 00000000 6 00000000
// 5 00000000 -> 5 00000000
// 4 00000000 4 00000000
// 3 00000000 3 00000000
// 2 00000000 2 00000000
// 1 11100000 1 10000000Sourcepub fn include_files(self, files: impl IntoIterator<Item = File>) -> Self
pub fn include_files(self, files: impl IntoIterator<Item = File>) -> Self
Apply a mask to self, only including the bits at positions in the given files.
§Example
let bb = Bitboard::with_ones([A1, B1, C1]);
let masked = bb.include_files([File::A, File::B]);
assert_eq!(masked, Bitboard::with_ones([A1, B1])); // C1 is not in file A or B
// ABCDEFGH ABCDEFGH
// 8 00000000 8 00000000
// 7 00000000 7 00000000
// 6 00000000 6 00000000
// 5 00000000 -> 5 00000000
// 4 00000000 4 00000000
// 3 00000000 3 00000000
// 2 00000000 2 00000000
// 1 11100000 1 11000000Sourcepub fn clear_file(self, file: File) -> Self
pub fn clear_file(self, file: File) -> Self
Apply a mask to self, setting the bits at positions in the given file to 0.
§Example
let bb = Bitboard::with_ones([C1, C2, B2]);
let cleared = bb.clear_file(File::C);
assert_eq!(cleared, Bitboard::with_one(B2)); // C1 and C2 have been cleared
// ABCDEFGH ABCDEFGH
// 8 00000000 8 00000000
// 7 00000000 7 00000000
// 6 00000000 6 00000000
// 5 00000000 -> 5 00000000
// 4 00000000 4 00000000
// 3 00000000 3 00000000
// 2 01100000 2 01000000
// 1 00100000 1 00000000Sourcepub fn clear_files(self, files: impl IntoIterator<Item = File>) -> Self
pub fn clear_files(self, files: impl IntoIterator<Item = File>) -> Self
Apply a mask to self, setting the bits at positions in the given files to 0.
§Example
let bb = Bitboard::with_ones([C1, C2, B2, D1]);
let cleared = bb.clear_files([File::C, File::D]);
assert_eq!(cleared, Bitboard::with_one(B2)); // C1, C2 and D1 have been cleared
// ABCDEFGH ABCDEFGH
// 8 00000000 8 00000000
// 7 00000000 7 00000000
// 6 00000000 6 00000000
// 5 00000000 -> 5 00000000
// 4 00000000 4 00000000
// 3 00000000 3 00000000
// 2 01100000 2 01000000
// 1 00110000 1 00000000Sourcepub fn include_rank(self, rank: Rank) -> Self
pub fn include_rank(self, rank: Rank) -> Self
Apply a mask to self, only including bits at positions in the given rank.
§Example
let bb = Bitboard::with_ones([A1, A2, G2]);
let rank_two = bb.include_rank(Rank::Two);
assert_eq!(rank_two, Bitboard::with_ones([A2, G2]));
// ABCDEFGH ABCDEFGH
// 8 00000000 8 00000000
// 7 00000000 7 00000000
// 6 00000000 6 00000000
// 5 00000000 -> 5 00000000
// 4 00000000 4 00000000
// 3 00000000 3 00000000
// 2 10000010 2 10000010
// 1 10000000 1 00000000Sourcepub fn include_ranks(self, ranks: impl IntoIterator<Item = Rank>) -> Self
pub fn include_ranks(self, ranks: impl IntoIterator<Item = Rank>) -> Self
Apply a mask to self, only including bits at positions in the given ranks.
§Example
let bb = Bitboard::with_ones([A1, A2, B2, F3]);
let rank_two_and_three = bb.include_ranks([Rank::Two, Rank::Three]);
assert_eq!(rank_two_and_three, Bitboard::with_ones([A2, B2, F3])); // A1 is not in rank two or three
// ABCDEFGH ABCDEFGH
// 8 00000000 8 00000000
// 7 00000000 7 00000000
// 6 00000000 6 00000000
// 5 00000000 -> 5 00000000
// 4 00000000 4 00000000
// 3 00000100 3 00000100
// 2 11000000 2 11000000
// 1 10000000 1 00000000Sourcepub fn clear_rank(self, rank: Rank) -> Self
pub fn clear_rank(self, rank: Rank) -> Self
Apply a mask to self, setting the bits at positions in the given rank to 0.
§Example
let bb = Bitboard::with_ones([C1, C2, B2]);
let without_rank_1 = bb.clear_rank(Rank::One);
assert_eq!(without_rank_1, Bitboard::with_ones([C2, B2])); // C1 has been cleared
// ABCDEFGH ABCDEFGH
// 8 00000000 8 00000000
// 7 00000000 7 00000000
// 6 00000000 6 00000000
// 5 00000000 -> 5 00000000
// 4 00000000 4 00000000
// 3 00000000 3 00000000
// 2 01100000 2 01100000
// 1 00100000 1 00000000Sourcepub fn clear_ranks(self, ranks: impl IntoIterator<Item = Rank>) -> Self
pub fn clear_ranks(self, ranks: impl IntoIterator<Item = Rank>) -> Self
Apply a mask to self, setting the bits at positions in the given ranks to 0.
§Example
let bb = Bitboard::with_ones([C1, C2, B2, D3]);
let cleared = bb.clear_ranks([Rank::Two, Rank::Three]);
assert_eq!(cleared, Bitboard::with_one(C1)); // C2, B2, D3 have been cleared
// ABCDEFGH ABCDEFGH
// 8 00000000 8 00000000
// 7 00000000 7 00000000
// 6 00000000 6 00000000
// 5 00000000 -> 5 00000000
// 4 00000000 4 00000000
// 3 00010000 3 00000000
// 2 01100000 2 00000000
// 1 00100000 1 00100000Sourcepub fn up_ray(from: Position) -> Self
pub fn up_ray(from: Position) -> Self
Create a Bitboard, setting each bit at positions in a ray starting at from and going straight up to 1.
§Example
let bb = Bitboard::up_ray(C5);
assert_eq!(bb, Bitboard::with_ones([C5, C6, C7, C8]));
// ABCDEFGH
// 8 00100000
// 7 00100000
// 6 00100000
// 5 00100000
// 4 00000000
// 3 00000000
// 2 00000000
// 1 00000000Sourcepub fn up_right_ray(from: Position) -> Self
pub fn up_right_ray(from: Position) -> Self
Create a Bitboard, setting each bit at positions in a ray starting at from and going diagonally up and to the right to 1.
§Example
let bb = Bitboard::up_right_ray(C5);
assert_eq!(bb, Bitboard::with_ones([C5, D6, E7, F8]));
// ABCDEFGH
// 8 00000100
// 7 00001000
// 6 00010000
// 5 00100000
// 4 00000000
// 3 00000000
// 2 00000000
// 1 00000000Sourcepub fn right_ray(from: Position) -> Self
pub fn right_ray(from: Position) -> Self
Create a Bitboard, setting each bit at positions in a ray starting at from and going straight to the right to 1.
§Example
let bb = Bitboard::right_ray(C5);
assert_eq!(bb, Bitboard::with_ones([C5, D5, E5, F5, G5, H5]));
// ABCDEFGH
// 8 00000000
// 7 00000000
// 6 00000000
// 5 00111111
// 4 00000000
// 3 00000000
// 2 00000000
// 1 00000000Sourcepub fn down_right_ray(from: Position) -> Self
pub fn down_right_ray(from: Position) -> Self
Create a Bitboard, setting each bit at positions in a ray starting at from and going diagonally down and to the right to 1.
§Example
let bb = Bitboard::down_right_ray(C5);
assert_eq!(bb, Bitboard::with_ones([C5, D4, E3, F2, G1]));
// ABCDEFGH
// 8 00000000
// 7 00000000
// 6 00000000
// 5 00100000
// 4 00010000
// 3 00001000
// 2 00000100
// 1 00000010Sourcepub fn down_ray(from: Position) -> Self
pub fn down_ray(from: Position) -> Self
Create a Bitboard, setting each bit at positions in a ray starting at from and going straight down to 1.
§Example
let bb = Bitboard::down_ray(C5);
assert_eq!(bb, Bitboard::with_ones([C5, C4, C3, C2, C1]));
// ABCDEFGH
// 8 00000000
// 7 00000000
// 6 00000000
// 5 00100000
// 4 00100000
// 3 00100000
// 2 00100000
// 1 00100000Sourcepub fn down_left_ray(from: Position) -> Self
pub fn down_left_ray(from: Position) -> Self
Create a Bitboard, setting each bit at positions in a ray starting at from and going diagonally down and to the left to 1.
§Example
let bb = Bitboard::down_left_ray(C5);
assert_eq!(bb, Bitboard::with_ones([C5, B4, A3]));
// ABCDEFGH
// 8 00000000
// 7 00000000
// 6 00000000
// 5 00100000
// 4 01000000
// 3 10000000
// 2 00000000
// 1 00000000Sourcepub fn left_ray(from: Position) -> Self
pub fn left_ray(from: Position) -> Self
Create a Bitboard, setting each bit at positions in a ray starting at from and going straight left to 1.
§Example
let bb = Bitboard::left_ray(C5);
assert_eq!(bb, Bitboard::with_ones([C5, B5, A5]));
// ABCDEFGH
// 8 00000000
// 7 00000000
// 6 00000000
// 5 11100000
// 4 00000000
// 3 00000000
// 2 00000000
// 1 00000000Sourcepub fn up_left_ray(from: Position) -> Self
pub fn up_left_ray(from: Position) -> Self
Create a Bitboard, setting each bit at positions in a ray starting at from and going diagonally up and to the left to 1.
§Example
let bb = Bitboard::up_left_ray(C5);
assert_eq!(bb, Bitboard::with_ones([C5, B6, A7]));
// ABCDEFGH
// 8 00000000
// 7 10000000
// 6 01000000
// 5 00100000
// 4 00000000
// 3 00000000
// 2 00000000
// 1 00000000Sourcepub fn white_pawn_targets(
pos: Position,
white_occupancy: Self,
black_occupancy: Self,
) -> Self
pub fn white_pawn_targets( pos: Position, white_occupancy: Self, black_occupancy: Self, ) -> Self
Returns a Bitboard describing valid target squares for a white pawn on pos.
§Example
let white = Bitboard::with_ones([]); // white has no pieces on the board
let black = Bitboard::with_ones([C5]); // black has a piece at C5
// a white pawn at D4 can either move to C5 (taking blacks piece), or move to D5
assert_eq!(Bitboard::white_pawn_targets(D4, white, black), Bitboard::with_ones([C5, D5]));Sourcepub fn black_pawn_targets(
pos: Position,
white_occupancy: Self,
black_occupancy: Self,
) -> Self
pub fn black_pawn_targets( pos: Position, white_occupancy: Self, black_occupancy: Self, ) -> Self
Returns a Bitboard describing valid target squares for a black pawn on pos.
§Example
let white = Bitboard::with_ones([C3]); // White has a piece at C3
let black = Bitboard::with_ones([D3]); // Black has a piece at D3
// A black pawn at D4 can move to C3 (taking whites piece). Note that it can't move to D3, since black already has a piece there.
assert_eq!(Bitboard::black_pawn_targets(D4, white, black), Bitboard::with_ones([C3]));Sourcepub fn white_king_targets(pos: Position, white_occupancy: Self) -> Self
pub fn white_king_targets(pos: Position, white_occupancy: Self) -> Self
Returns a Bitboard describing valid target squares for a white king on pos.
§Example
let white_pieces = Bitboard::with_ones([B4]);
// A white king can move to any square one Manhattan distance step away.
// There is a white piece on B4, which blocks the white king.
assert_eq!(Bitboard::white_king_targets(C4, white_pieces), Bitboard::with_ones([C5, D5, D4, D3, C3, B3, B5]));
// ABCDEFGH ABCDEFGH
// 8 00000000 8 00000000
// 7 00000000 7 00000000
// 6 00000000 6 00000000
// 5 00000000 -> 5 01110000
// 4 01x00000 4 00010000
// 3 00000000 3 01110000
// 2 00000000 2 00000000
// 1 00000000 1 00000000Sourcepub fn black_king_targets(pos: Position, black_occupancy: Self) -> Self
pub fn black_king_targets(pos: Position, black_occupancy: Self) -> Self
Returns a Bitboard describing valid target squares for a black king on pos.
§Example
let black_pieces = Bitboard::with_ones([B4]);
// A black king can move to any square one Manhattan distance step away.
// There is a black piece on B4, which blocks the black king.
assert_eq!(Bitboard::black_king_targets(C4, black_pieces), Bitboard::with_ones([C5, D5, D4, D3, C3, B3, B5]));
// ABCDEFGH ABCDEFGH
// 8 00000000 8 00000000
// 7 00000000 7 00000000
// 6 00000000 6 00000000
// 5 00000000 -> 5 01110000
// 4 01x00000 4 00010000
// 3 00000000 3 01110000
// 2 00000000 2 00000000
// 1 00000000 1 00000000Sourcepub fn knight_targets(pos: Position, self_occupancy: Self) -> Self
pub fn knight_targets(pos: Position, self_occupancy: Self) -> Self
Returns a Bitboard describing valid target squares for a knight on pos.
§Notes
self_occupancy should be a Bitboard representing the pieces with the same color as the given knight.
§Example
let white_pieces = Bitboard::with_ones([A6, C6]);
// a white knight on B4 can't move to A6 or C6 if there are white pieces there
assert_eq!(Bitboard::knight_targets(B4, white_pieces), Bitboard::with_ones([D5, D3, C2, A2]));
// ABCDEFGH ABCDEFGH
// 8 00000000 8 00000000
// 7 00000000 7 00000000
// 6 00000000 6 10100000
// 5 00000000 -> 5 00010000
// 4 01000000 4 00000000
// 3 00000000 3 00010000
// 2 00000000 2 10100000
// 1 00000000 1 00000000Sourcepub fn white_bishop_targets(
pos: Position,
white_occupancy: Self,
black_occupancy: Self,
) -> Self
pub fn white_bishop_targets( pos: Position, white_occupancy: Self, black_occupancy: Self, ) -> Self
Returns a Bitboard describing valid target squares for a white bishop on pos.
§Example
let white_pieces = Bitboard::with_one(E1);
let black_pieces = Bitboard::with_one(D6);
// a white bishop on B4 can move to any empty square on its diagonals,
// there is a white piece on E1, which blocks the white bishop
// there is a black piece on D6, which the white bishop can take, but not move through
assert_eq!(Bitboard::white_bishop_targets(B4, white_pieces, black_pieces), Bitboard::with_ones([A3, A5, C5, D6, C3, D2]));
// ABCDEFGH ABCDEFGH
// 8 00000000 8 00000000
// 7 00000000 7 00000000
// 6 00010000 6 00010000
// 5 00000000 -> 5 10100000
// 4 0x000000 4 0x000000
// 3 00000000 3 10100000
// 2 00000000 2 00010000
// 1 00000000 1 00000000Sourcepub fn black_bishop_targets(
pos: Position,
white_occupancy: Self,
black_occupancy: Self,
) -> Self
pub fn black_bishop_targets( pos: Position, white_occupancy: Self, black_occupancy: Self, ) -> Self
Returns a Bitboard describing valid target squares for a black bishop on pos.
§Example
let white_pieces = Bitboard::with_one(D6);
let black_pieces = Bitboard::with_one(D2);
// A black bishop on B4 can move to any empty square on its diagonals.
// There is a black piece on D2, which blocks the black bishop.
// There is a white piece on D6, which the black bishop can take, but not move through.
assert_eq!(Bitboard::black_bishop_targets(B4, white_pieces, black_pieces), Bitboard::with_ones([A3, A5, C5, D6, C3]));
// ABCDEFGH ABCDEFGH
// 8 00000000 8 00000000
// 7 00000000 7 00000000
// 6 00010000 6 00010000
// 5 00000000 -> 5 10100000
// 4 0x000000 4 0x000000
// 3 00000000 3 10100000
// 2 00000000 2 00000000
// 1 00000000 1 00000000Sourcepub fn white_rook_targets(
pos: Position,
white_occupancy: Self,
black_occupancy: Self,
) -> Self
pub fn white_rook_targets( pos: Position, white_occupancy: Self, black_occupancy: Self, ) -> Self
Returns a Bitboard describing valid target squares for a white rook on pos.
§Example
let white_pieces = Bitboard::with_one(G4);
let black_pieces = Bitboard::with_one(D6);
// A white rook can move to any empty squares on its cardinals.
// There is a white piece on G4, which blocks the white rook.
// There is a black piece on D6, which the white rook can take, but not move through.
assert_eq!(Bitboard::white_rook_targets(D4, white_pieces, black_pieces), Bitboard::with_ones([A4, B4, C4, D5, D6, D3, D2, D1, E4, F4]));
// ABCDEFGH ABCDEFGH
// 8 00000000 8 00000000
// 7 00000000 7 00000000
// 6 00010000 6 00010000
// 5 00000000 -> 5 00010000
// 4 000x0000 4 11101100
// 3 00000000 3 00010000
// 2 00000000 2 00010000
// 1 00000000 1 00010000Sourcepub fn black_rook_targets(
pos: Position,
white_occupancy: Self,
black_occupancy: Self,
) -> Self
pub fn black_rook_targets( pos: Position, white_occupancy: Self, black_occupancy: Self, ) -> Self
Returns a Bitboard describing valid target squares for a black rook on pos.
§Example
let white_pieces = Bitboard::with_one(D6);
let black_pieces = Bitboard::with_one(G4);
// A black rook can move to any empty squares on its cardinals.
// There is a white piece on D6, which the black rook can take, but not move through.
// There is a black piece on G4, which blocks the black rook.
assert_eq!(Bitboard::black_rook_targets(D4, white_pieces, black_pieces), Bitboard::with_ones([A4, B4, C4, D5, D6, D3, D2, D1, E4, F4]));
// ABCDEFGH ABCDEFGH
// 8 00000000 8 00000000
// 7 00000000 7 00000000
// 6 00010000 6 00010000
// 5 00000000 -> 5 00010000
// 4 000x0000 4 11101100
// 3 00000000 3 00010000
// 2 00000000 2 00010000
// 1 00000000 1 00010000Sourcepub fn white_queen_targets(
pos: Position,
white_occupancy: Self,
black_occupancy: Self,
) -> Self
pub fn white_queen_targets( pos: Position, white_occupancy: Self, black_occupancy: Self, ) -> Self
Returns a Bitboard describing valid target squares for a white queen on pos.
§Example
let white_pieces = Bitboard::with_one(G4);
let black_pieces = Bitboard::with_one(D6);
// A white queen can move to any empty squares on its cardinals and diagonals.
// There is a black piece on D6, which the white queen can take, but not move through.
// There is a white piece on G4, which blocks the white queen.
assert_eq!(Bitboard::white_queen_targets(D4, white_pieces, black_pieces),
Bitboard::with_ones([A1, D1, G1, B2, D2, F2, C3, D3, E3, A4, B4, C4, E4, F4, C5, D5, E5, B6, D6, F6, A7, G7, H8]));
// ABCDEFGH ABCDEFGH
// 8 00000000 8 00000001
// 7 00000000 7 10000010
// 6 00010000 6 01010100
// 5 00000000 -> 5 00111000
// 4 000x0000 4 11101100
// 3 00000000 3 00111000
// 2 00000000 2 01010100
// 1 00000000 1 10010010Sourcepub fn black_queen_targets(
pos: Position,
white_occupancy: Self,
black_occupancy: Self,
) -> Self
pub fn black_queen_targets( pos: Position, white_occupancy: Self, black_occupancy: Self, ) -> Self
Returns a Bitboard describing valid target squares for a black queen on pos.
§Example
let white_pieces = Bitboard::with_one(D6);
let black_pieces = Bitboard::with_one(G4);
// A black queen can move to any empty squares on its cardinals and diagonals.
// There is a white piece on D6, which the black queen can take, but not move through.
// There is a black piece on G4, which blocks the black queen.
assert_eq!(Bitboard::black_queen_targets(D4, white_pieces, black_pieces),
Bitboard::with_ones([A1, D1, G1, B2, D2, F2, C3, D3, E3, A4, B4, C4, E4, F4, C5, D5, E5, B6, D6, F6, A7, G7, H8]));
// ABCDEFGH ABCDEFGH
// 8 00000000 8 00000001
// 7 00000000 7 10000010
// 6 00010000 6 01010100
// 5 00000000 -> 5 00111000
// 4 000x0000 4 11101100
// 3 00000000 3 00111000
// 2 00000000 2 01010100
// 1 00000000 1 10010010Sourcepub fn first_position(self) -> Option<Position>
pub fn first_position(self) -> Option<Position>
Returns the first position in self where the bit is 1, or None if all bits are 0.
§Notes
Searches in the following order: A1, B1, C1, ..., F8, G8, H8.
§Example
let bb = Bitboard::with_ones([A5, C7, A3]);
assert_eq!(bb.first_position(), Some(A3));
assert_eq!(Bitboard::empty().first_position(), None);Trait Implementations§
Source§impl BitAndAssign for Bitboard
impl BitAndAssign for Bitboard
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&= operation. Read moreSource§impl BitAndAssign<Position> for Bitboard
impl BitAndAssign<Position> for Bitboard
Source§fn bitand_assign(&mut self, rhs: Position)
fn bitand_assign(&mut self, rhs: Position)
&= operation. Read moreSource§impl BitAndAssign<u64> for Bitboard
impl BitAndAssign<u64> for Bitboard
Source§fn bitand_assign(&mut self, rhs: u64)
fn bitand_assign(&mut self, rhs: u64)
&= operation. Read moreSource§impl BitOrAssign for Bitboard
impl BitOrAssign for Bitboard
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|= operation. Read moreSource§impl BitOrAssign<Position> for Bitboard
impl BitOrAssign<Position> for Bitboard
Source§fn bitor_assign(&mut self, rhs: Position)
fn bitor_assign(&mut self, rhs: Position)
|= operation. Read moreSource§impl BitOrAssign<u64> for Bitboard
impl BitOrAssign<u64> for Bitboard
Source§fn bitor_assign(&mut self, rhs: u64)
fn bitor_assign(&mut self, rhs: u64)
|= operation. Read moreSource§impl BitXorAssign for Bitboard
impl BitXorAssign for Bitboard
Source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^= operation. Read moreSource§impl BitXorAssign<Position> for Bitboard
impl BitXorAssign<Position> for Bitboard
Source§fn bitxor_assign(&mut self, rhs: Position)
fn bitxor_assign(&mut self, rhs: Position)
^= operation. Read moreSource§impl BitXorAssign<u64> for Bitboard
impl BitXorAssign<u64> for Bitboard
Source§fn bitxor_assign(&mut self, rhs: u64)
fn bitxor_assign(&mut self, rhs: u64)
^= operation. Read more