typing improvements

This commit is contained in:
2025-03-08 23:25:04 -05:00
parent 52e7ed7386
commit f64aa16143
3 changed files with 14 additions and 11 deletions

View File

@@ -6,13 +6,13 @@ use std::{cmp::Ordering, fmt};
/// Map of all points on the board against some type T
/// Used to index like so: example[i][j]
/// with each coordinate
pub struct PosMap<T: Default>(ArrayVec<T, { Board::BOARD_AREA as usize }>);
pub struct PosMap<T: Default>(ArrayVec<T, { Board::BOARD_AREA.0 as usize }>);
impl<T: Default> PosMap<T> {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self(ArrayVec::from_iter(
(0..Board::BOARD_AREA).map(|_| Default::default()),
(0..Board::BOARD_AREA.0).map(|_| Default::default()),
))
}
@@ -117,7 +117,7 @@ impl Board {
pub const BOARD_SIZE: CoordAxis = 8;
/// Area of the board
pub const BOARD_AREA: CoordAxis = Self::BOARD_SIZE.pow(2);
pub const BOARD_AREA: CoordPair = CoordPair(CoordPair(Self::BOARD_SIZE).0.pow(2));
/// Create a new empty board
#[allow(clippy::new_without_default)]
@@ -156,7 +156,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, j).into()))
(0..Self::BOARD_AREA.0).map(CoordPair)
}
/// Returns an iterator of all possible moves a `color` can make
@@ -248,12 +248,16 @@ impl Board {
let count = flip_mask.count();
// Apply the flips
*self.board_mut(starting_color) |= flip_mask;
*self.board_mut(starting_color.flip()) &= !flip_mask;
self.apply_flip_mask(starting_color, flip_mask);
count
}
fn apply_flip_mask(&mut self, color: Piece, flip_mask: BitBoard) {
*self.board_mut(color) |= flip_mask;
*self.board_mut(color.flip()) &= !flip_mask;
}
/// Propegate piece captures originating from (i, j)
/// DO NOT USE THIS ALONE, this should be called as a part of
/// [`Board::place`] or [`Board::place_and_prop_unchecked`]