diff --git a/bitboard/src/bitboard.rs b/bitboard/src/bitboard.rs index 4904c3e..b8a56ef 100644 --- a/bitboard/src/bitboard.rs +++ b/bitboard/src/bitboard.rs @@ -80,6 +80,20 @@ impl BitBoard { !(self & square_bitboard).is_empty() } + /// The number of 1 bits in the BitBoard. + /// + /// ## Examples + /// + /// ``` + /// use chessfriend_bitboard::BitBoard; + /// assert_eq!(BitBoard::EMPTY.population_count(), 0); + /// assert_eq!(BitBoard::new(0b01011110010).population_count(), 6); + /// assert_eq!(BitBoard::FULL.population_count(), 64); + /// ``` + pub fn population_count(&self) -> u32 { + self.0.count_ones() + } + pub fn set_square(&mut self, sq: Square) { let sq_bb: BitBoard = sq.into(); *self |= sq_bb