diff --git a/bitboard/src/bitboard.rs b/bitboard/src/bitboard.rs index 8d8d8dc..5efbed0 100644 --- a/bitboard/src/bitboard.rs +++ b/bitboard/src/bitboard.rs @@ -67,16 +67,41 @@ impl BitBoard { } impl BitBoard { - pub fn as_bits(&self) -> &u64 { + pub const fn as_bits(&self) -> &u64 { &self.0 } - pub fn is_empty(&self) -> bool { + /// Returns `true` if the [`BitBoard`] has no bits set. + /// + /// ## Examples + /// + /// ``` + /// use chessfriend_bitboard::BitBoard; + /// assert!(BitBoard::EMPTY.is_populated()); + /// assert!(!BitBoard::FULL.is_populated()); + /// assert!(!BitBoard::new(0b1000).is_populated()); + /// ``` + pub const fn is_empty(&self) -> bool { self.0 == 0 } - pub fn is_set(self, sq: Square) -> bool { - let square_bitboard: BitBoard = sq.into(); + /// Returns `true` if the [`BitBoard`] has at least one bit set. + /// + /// ## Examples + /// + /// ``` + /// use chessfriend_bitboard::BitBoard; + /// assert!(!BitBoard::EMPTY.is_populated()); + /// assert!(BitBoard::FULL.is_populated()); + /// assert!(BitBoard::new(0b1).is_populated()); + /// ``` + pub const fn is_populated(&self) -> bool { + self.0 != 0 + } + + /// Returns `true` if this [`BitBoard`] has the bit corresponding to `square` set. + pub fn is_set(self, square: Square) -> bool { + let square_bitboard: BitBoard = square.into(); !(self & square_bitboard).is_empty() } @@ -90,7 +115,7 @@ impl BitBoard { /// assert_eq!(BitBoard::new(0b01011110010).population_count(), 6); /// assert_eq!(BitBoard::FULL.population_count(), 64); /// ``` - pub fn population_count(&self) -> u32 { + pub const fn population_count(&self) -> u32 { self.0.count_ones() } diff --git a/bitboard/src/library.rs b/bitboard/src/library.rs index 5e74259..f87084b 100644 --- a/bitboard/src/library.rs +++ b/bitboard/src/library.rs @@ -1,5 +1,13 @@ // Eryn Wells +//! # The BitBoard Library +//! +//! This module implements a collection of commonly used BitBoards that can be +//! looked up efficiently as needed. +//! +//! The `library()` method returns a static instance of a `Library`, which +//! provides getters for all available BitBoards. + use crate::BitBoard; use chessfriend_core::{Color, Direction, Square}; use std::sync::OnceLock;