iterator fixes

This commit is contained in:
2025-02-06 16:13:11 -05:00
parent 1bed0b61ad
commit 3681fd7e41
4 changed files with 35 additions and 41 deletions

View File

@@ -74,6 +74,14 @@ impl Board {
self
}
pub fn possible_moves(&self, color: Piece) -> Box<dyn Iterator<Item = (usize, usize)> + '_> {
Box::new(
(0..BOARD_SIZE)
.flat_map(|i| (0..BOARD_SIZE).map(move |j| (i, j)))
.filter(move |(i, j)| self.what_if(*i, *j, color).is_some()),
)
}
/// Returns a mutable reference to a place on the [`Board`]
/// at (i, j)
pub const fn get_mut(&mut self, i: usize, j: usize) -> &mut Option<Piece> {