Add 'Bitboard::count'
This commit is contained in:
parent
7a7e7f3665
commit
8261b0c06b
|
@ -37,6 +37,12 @@ impl Bitboard {
|
|||
Bitboard(0b00000000_11111111_00000000_00000000_00000000_00000000_00000000_00000000),
|
||||
Bitboard(0b11111111_00000000_00000000_00000000_00000000_00000000_00000000_00000000),
|
||||
];
|
||||
|
||||
/// Count the number of pieces in the [Bitboard].
|
||||
#[inline(always)]
|
||||
pub fn count(self) -> u32 {
|
||||
self.0.count_ones()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Bitboard {
|
||||
|
@ -170,6 +176,13 @@ mod test {
|
|||
use super::*;
|
||||
use crate::board::square::*;
|
||||
|
||||
#[test]
|
||||
fn count() {
|
||||
assert_eq!(Bitboard::EMPTY.count(), 0);
|
||||
assert_eq!(Bitboard::FILES[0].count(), 8);
|
||||
assert_eq!(Bitboard::ALL.count(), 64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn iter() {
|
||||
assert_eq!(Bitboard::EMPTY.into_iter().collect::<Vec<_>>(), Vec::new());
|
||||
|
|
Loading…
Reference in a new issue