[bitboard] Implement BitBoard::population_count()
Uses u64::count_ones() to return the population count of the BitBoard.
This commit is contained in:
parent
7b97060ba2
commit
deea23352b
1 changed files with 14 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue