diff --git a/bitboard/src/bitboard.rs b/bitboard/src/bitboard.rs index 2453cce..66a5336 100644 --- a/bitboard/src/bitboard.rs +++ b/bitboard/src/bitboard.rs @@ -18,8 +18,8 @@ macro_rules! moves_getter { } impl BitBoard { - pub const EMPTY: BitBoard = BitBoard(0); - pub const FULL: BitBoard = BitBoard(0xFFFFFFFFFFFFFFFF); + pub const EMPTY: BitBoard = BitBoard(u64::MIN); + pub const FULL: BitBoard = BitBoard(u64::MAX); pub const fn empty() -> BitBoard { BitBoard(0) @@ -104,6 +104,17 @@ impl BitBoard { *self &= !sq_bb } + /// Returns `true` if this BitBoard represents a single square. + /// + /// ## Examples + /// + /// ``` + /// use chessfriend_bitboard::BitBoard; + /// assert!(!BitBoard::EMPTY.is_single_square(), "Empty bitboards represent no squares"); + /// assert!(!BitBoard::FULL.is_single_square(), "Full bitboards represent all the squares"); + /// assert!(!BitBoard::new(0b010011110101101100).is_single_square(), "This bitboard represents a bunch of squares"); + /// assert!(BitBoard::new(0b10000000000000).is_single_square()); + /// ``` pub fn is_single_square(&self) -> bool { self.0.is_power_of_two() } @@ -149,7 +160,7 @@ impl Default for BitBoard { impl From for BitBoard { fn from(value: Square) -> Self { - BitBoard(1 << value as u64) + BitBoard(1u64 << value as u32) } } diff --git a/bitboard/src/library.rs b/bitboard/src/library.rs index afc4240..5e74259 100644 --- a/bitboard/src/library.rs +++ b/bitboard/src/library.rs @@ -4,7 +4,7 @@ use crate::BitBoard; use chessfriend_core::{Color, Direction, Square}; use std::sync::OnceLock; -pub(super) const RANKS: [BitBoard; 8] = [ +pub(crate) const RANKS: [BitBoard; 8] = [ BitBoard(0xFF << 0 * 8), BitBoard(0xFF << 1 * 8), BitBoard(0xFF << 2 * 8), @@ -15,7 +15,7 @@ pub(super) const RANKS: [BitBoard; 8] = [ BitBoard(0xFF << 7 * 8), ]; -pub(super) const FILES: [BitBoard; 8] = [ +pub(crate) const FILES: [BitBoard; 8] = [ BitBoard(0x0101010101010101 << 0), BitBoard(0x0101010101010101 << 1), BitBoard(0x0101010101010101 << 2),