simplify board functions

This commit is contained in:
Simon Gardling 2025-02-27 23:32:20 -05:00
parent 5c3884653e
commit cbf47482ad
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D

View File

@ -123,9 +123,7 @@ impl Board {
/// Provides an iterator of all possible positions on the board
pub fn all_positions() -> impl Iterator<Item = CoordPair> {
(0..Self::BOARD_SIZE).flat_map(|i| {
(0..Self::BOARD_SIZE).map(move |j| (i as CoordAxis, j as CoordAxis).into())
})
(0..Self::BOARD_SIZE).flat_map(|i| (0..Self::BOARD_SIZE).map(move |j| (i, j).into()))
}
/// Returns an iterator of all possible moves a `color` can make
@ -133,20 +131,6 @@ impl Board {
Self::all_positions().filter(move |&coord| self.would_prop(coord, color))
}
pub fn sides() -> impl Iterator<Item = (CoordAxis, CoordAxis)> {
(0..Self::BOARD_SIZE)
.map(|i| (i, Self::BOARD_SIZE - 1))
.chain((0..Self::BOARD_SIZE).map(|i| (i, 0)))
.chain((0..Self::BOARD_SIZE).map(|j| (Self::BOARD_SIZE - 1, j)))
.chain((0..Self::BOARD_SIZE).map(|j| (0, j)))
}
pub fn corners() -> impl Iterator<Item = (CoordAxis, CoordAxis)> {
[0, Self::BOARD_SIZE - 1]
.into_iter()
.flat_map(|i| [0, Self::BOARD_SIZE - 1].into_iter().map(move |j| (i, j)))
}
/// Get a reference to a backing [`BitBoard`]
const fn board(&self, color: Piece) -> &BitBoard {
match color {