From 4960286557c7c6db972e60e9e230822068f517de Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 14 Apr 2024 16:10:41 +0100 Subject: [PATCH] Simplify 'BitboardIterator' --- src/board/bitboard/iterator.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/board/bitboard/iterator.rs b/src/board/bitboard/iterator.rs index 7c01a9a..f5711ee 100644 --- a/src/board/bitboard/iterator.rs +++ b/src/board/bitboard/iterator.rs @@ -2,11 +2,11 @@ /// [Bitboard]. use crate::board::Bitboard; -pub struct BitboardIterator(u64); +pub struct BitboardIterator(Bitboard); impl BitboardIterator { pub fn new(board: Bitboard) -> Self { - Self(board.0) + Self(board) } } @@ -14,17 +14,15 @@ impl Iterator for BitboardIterator { type Item = crate::board::Square; fn next(&mut self) -> Option { - if self.0 == 0 { - None - } else { - let lsb = self.0.trailing_zeros() as usize; - self.0 ^= 1 << lsb; - Some(crate::board::Square::from_index(lsb)) - } + let res = self.0.any_square(); + if let Some(square) = res { + self.0 ^= square; + }; + res } fn size_hint(&self) -> (usize, Option) { - let size = self.0.count_ones() as usize; + let size = self.0.count() as usize; (size, Some(size)) }