From 3239f288d773047d6b18b7b787e39fe858b757cc Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Mon, 29 Jan 2024 15:00:53 -0800 Subject: [PATCH] [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. --- bitboard/src/bitboard.rs | 22 +++++++++++++++------- bitboard/src/library.rs | 15 +++++++++++++-- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/bitboard/src/bitboard.rs b/bitboard/src/bitboard.rs index 10620e5..b2e1a4c 100644 --- a/bitboard/src/bitboard.rs +++ b/bitboard/src/bitboard.rs @@ -1,6 +1,6 @@ // Eryn Wells -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 { diff --git a/bitboard/src/library.rs b/bitboard/src/library.rs index 6e51f24..41951c7 100644 --- a/bitboard/src/library.rs +++ b/bitboard/src/library.rs @@ -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();