simplify board functions
This commit is contained in:
parent
5c3884653e
commit
cbf47482ad
@ -123,9 +123,7 @@ impl Board {
|
|||||||
|
|
||||||
/// Provides an iterator of all possible positions on the board
|
/// Provides an iterator of all possible positions on the board
|
||||||
pub fn all_positions() -> impl Iterator<Item = CoordPair> {
|
pub fn all_positions() -> impl Iterator<Item = CoordPair> {
|
||||||
(0..Self::BOARD_SIZE).flat_map(|i| {
|
(0..Self::BOARD_SIZE).flat_map(|i| (0..Self::BOARD_SIZE).map(move |j| (i, j).into()))
|
||||||
(0..Self::BOARD_SIZE).map(move |j| (i as CoordAxis, j as CoordAxis).into())
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator of all possible moves a `color` can make
|
/// 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))
|
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`]
|
/// Get a reference to a backing [`BitBoard`]
|
||||||
const fn board(&self, color: Piece) -> &BitBoard {
|
const fn board(&self, color: Piece) -> &BitBoard {
|
||||||
match color {
|
match color {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user