Simplify 'BitboardIterator'
All checks were successful
ci/woodpecker/push/check Pipeline was successful
All checks were successful
ci/woodpecker/push/check Pipeline was successful
This commit is contained in:
parent
524e3b2c76
commit
4960286557
|
@ -2,11 +2,11 @@
|
||||||
/// [Bitboard].
|
/// [Bitboard].
|
||||||
use crate::board::Bitboard;
|
use crate::board::Bitboard;
|
||||||
|
|
||||||
pub struct BitboardIterator(u64);
|
pub struct BitboardIterator(Bitboard);
|
||||||
|
|
||||||
impl BitboardIterator {
|
impl BitboardIterator {
|
||||||
pub fn new(board: Bitboard) -> Self {
|
pub fn new(board: Bitboard) -> Self {
|
||||||
Self(board.0)
|
Self(board)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,17 +14,15 @@ impl Iterator for BitboardIterator {
|
||||||
type Item = crate::board::Square;
|
type Item = crate::board::Square;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
if self.0 == 0 {
|
let res = self.0.any_square();
|
||||||
None
|
if let Some(square) = res {
|
||||||
} else {
|
self.0 ^= square;
|
||||||
let lsb = self.0.trailing_zeros() as usize;
|
};
|
||||||
self.0 ^= 1 << lsb;
|
res
|
||||||
Some(crate::board::Square::from_index(lsb))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
let size = self.0.count_ones() as usize;
|
let size = self.0.count() as usize;
|
||||||
|
|
||||||
(size, Some(size))
|
(size, Some(size))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue