overhaul chain system
This made the code so fast, that the `board` benchmark became completely useless. So that benchmark was removed. Overall, we're looking at a futher 20% performance increase in `future_moves`
This commit is contained in:
@@ -11,42 +11,6 @@ type Chain = ArrayVec<CoordPair, { (Board::BOARD_SIZE - 1) as usize }>;
|
||||
/// A collection of chains (up vert, down vert, left horiz, right horiz, diagonals....)
|
||||
pub type ChainCollection = ArrayVec<Chain, 8>;
|
||||
|
||||
/// 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 }>);
|
||||
|
||||
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()),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn get(&self, coords: CoordPair) -> &T {
|
||||
&self.0[coords.0 as usize]
|
||||
}
|
||||
|
||||
pub fn set(&mut self, coords: CoordPair, value: T) {
|
||||
self.0[coords.0 as usize] = value;
|
||||
}
|
||||
}
|
||||
|
||||
type PosMapOrig<T> = [[T; Board::BOARD_SIZE as usize]; Board::BOARD_SIZE as usize];
|
||||
|
||||
impl<T: Default + Copy> From<PosMapOrig<T>> for PosMap<T> {
|
||||
fn from(value: PosMapOrig<T>) -> Self {
|
||||
let mut new = Self::new();
|
||||
for i in 0..Board::BOARD_SIZE {
|
||||
for j in 0..Board::BOARD_SIZE {
|
||||
new.set((i, j).into(), value[i as usize][j as usize]);
|
||||
}
|
||||
}
|
||||
new
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a lookup map for adjacencies and chains from each position on the board
|
||||
pub fn gen_adj_lookup() -> PosMap<ChainCollection> {
|
||||
PosMap(
|
||||
|
||||
Reference in New Issue
Block a user