Add 'Bitboard::count'
This commit is contained in:
parent
db0a7e9f60
commit
61e7a4e8d1
|
@ -37,6 +37,12 @@ impl Bitboard {
|
||||||
Bitboard(0b00000000_11111111_00000000_00000000_00000000_00000000_00000000_00000000),
|
Bitboard(0b00000000_11111111_00000000_00000000_00000000_00000000_00000000_00000000),
|
||||||
Bitboard(0b11111111_00000000_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 {
|
impl Default for Bitboard {
|
||||||
|
@ -170,6 +176,13 @@ mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::board::square::*;
|
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]
|
#[test]
|
||||||
fn iter() {
|
fn iter() {
|
||||||
assert_eq!(Bitboard::EMPTY.into_iter().collect::<Vec<_>>(), Vec::new());
|
assert_eq!(Bitboard::EMPTY.into_iter().collect::<Vec<_>>(), Vec::new());
|
||||||
|
|
Loading…
Reference in a new issue