diff options
Diffstat (limited to 'src/bitboard.rs')
-rw-r--r-- | src/bitboard.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/bitboard.rs b/src/bitboard.rs index d7a4fdb..3df4902 100644 --- a/src/bitboard.rs +++ b/src/bitboard.rs @@ -22,11 +22,13 @@ pub fn print(bb: Bitboard, title: &str) { } /// Return bitboard cardinality, aka number of elements in the set -pub fn pop_count(bb: Bitboard) -> u8 { - if bb == 0 { - return 0; +pub fn pop_count(mut bb: Bitboard) -> u8 { + let mut count = 0; + while bb > 0 { + count += 1; + bb &= bb - 1; } - return pop_count(bb >> 1) + (bb & 1) as u8; + return count; } /// Return Bitboard with only Least Single Bit |