[bitboard] Bitboards for kingside and queenside per color

Add two small BitBoard slices that represent kingside and queenside squares per
color.

Add doc comments to DARK_SQUARES and LIGHT_SQUARES.
Add getters on BitBoard for getting a boardside bitboard.
Clean up imports. Import the whole library module and refer to library things in
BitBoard by path.
This commit is contained in:
Eryn Wells 2024-01-29 15:00:53 -08:00
parent d6bd6aec0f
commit 3239f288d7
2 changed files with 28 additions and 9 deletions

View file

@ -1,6 +1,6 @@
// Eryn Wells <eryn@erynwells.me>
use crate::library::{library, FILES, RANKS};
use crate::library;
use crate::LeadingBitScanner;
use chessfriend_core::{Color, Direction, Square};
use std::fmt;
@ -12,7 +12,7 @@ pub struct BitBoard(pub(crate) u64);
macro_rules! moves_getter {
($getter_name:ident) => {
pub fn $getter_name(sq: Square) -> BitBoard {
library().$getter_name(sq)
library::library().$getter_name(sq)
}
};
}
@ -28,24 +28,24 @@ impl BitBoard {
pub fn rank(rank: &u8) -> BitBoard {
debug_assert!(*rank < 8);
RANKS[*rank as usize]
library::RANKS[*rank as usize]
}
pub fn file(file: &u8) -> BitBoard {
debug_assert!(*file < 8);
FILES[*file as usize]
library::FILES[*file as usize]
}
pub fn ray(sq: Square, dir: Direction) -> BitBoard {
library().ray(sq, dir)
library::library().ray(sq, dir)
}
pub fn pawn_attacks(sq: Square, color: Color) -> BitBoard {
library().pawn_attacks(sq, color)
library::library().pawn_attacks(sq, color)
}
pub fn pawn_pushes(sq: Square, color: Color) -> BitBoard {
library().pawn_pushes(sq, color)
library::library().pawn_pushes(sq, color)
}
moves_getter!(knight_moves);
@ -53,6 +53,14 @@ impl BitBoard {
moves_getter!(rook_moves);
moves_getter!(queen_moves);
moves_getter!(king_moves);
pub const fn kingside(color: Color) -> &'static BitBoard {
&library::KINGSIDES[color as usize]
}
pub const fn queenside(color: Color) -> &'static BitBoard {
&library::QUEENSIDES[color as usize]
}
}
impl BitBoard {

View file

@ -26,9 +26,20 @@ pub(super) const FILES: [BitBoard; 8] = [
BitBoard(0x0101010101010101 << 7),
];
pub(super) const LIGHT_SQUARES: BitBoard =
/// Bitboards representing the kingside of the board, per color.
pub(crate) const KINGSIDES: [BitBoard; 2] =
[BitBoard(0xF0F0F0F0F0F0F0F0), BitBoard(0x0F0F0F0F0F0F0F0F)];
/// Bitboards representing the queenside of the board, per color.
pub(crate) const QUEENSIDES: [BitBoard; 2] =
[BitBoard(0x0F0F0F0F0F0F0F0F), BitBoard(0xF0F0F0F0F0F0F0F0)];
/// A bitboard representing the light squares.
pub(crate) const LIGHT_SQUARES: BitBoard =
BitBoard(0x5555 | 0x5555 << 16 | 0x5555 << 32 | 0x5555 << 48);
pub(super) const DARK_SQUARES: BitBoard = BitBoard(!LIGHT_SQUARES.0);
/// A bitboad representing the dark squares
pub(crate) const DARK_SQUARES: BitBoard = BitBoard(!LIGHT_SQUARES.0);
pub(super) fn library() -> &'static MoveLibrary {
static MOVE_LIBRARY_INIT: Once = Once::new();