switch coordinates to global 'Coord' type
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use super::{
|
||||
board::Coord,
|
||||
misc::{diag_raw, get_index, split_from},
|
||||
Board,
|
||||
};
|
||||
@@ -6,7 +7,7 @@ use arrayvec::ArrayVec;
|
||||
use std::collections::HashSet;
|
||||
|
||||
/// A chain of positions across the board
|
||||
type Chain = ArrayVec<(usize, usize), { Board::BOARD_SIZE - 1 }>;
|
||||
type Chain = ArrayVec<(Coord, Coord), { (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>;
|
||||
@@ -14,7 +15,7 @@ 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 }>);
|
||||
pub struct PosMap<T: Default>(ArrayVec<T, { Board::BOARD_AREA as usize }>);
|
||||
|
||||
impl<T: Default> PosMap<T> {
|
||||
#[allow(clippy::new_without_default)]
|
||||
@@ -24,7 +25,7 @@ impl<T: Default> PosMap<T> {
|
||||
))
|
||||
}
|
||||
|
||||
pub fn get(&self, row: usize, col: usize) -> &T {
|
||||
pub fn get(&self, row: Coord, col: Coord) -> &T {
|
||||
let index = get_index(row, col);
|
||||
|
||||
debug_assert!(
|
||||
@@ -33,10 +34,10 @@ impl<T: Default> PosMap<T> {
|
||||
index
|
||||
);
|
||||
|
||||
unsafe { self.0.get_unchecked(index) }
|
||||
unsafe { self.0.get_unchecked(index as usize) }
|
||||
}
|
||||
|
||||
pub fn set(&mut self, row: usize, col: usize, value: T) {
|
||||
pub fn set(&mut self, row: Coord, col: Coord, value: T) {
|
||||
let index = get_index(row, col);
|
||||
debug_assert!(
|
||||
Board::BOARD_AREA + 1 >= index,
|
||||
@@ -44,7 +45,7 @@ impl<T: Default> PosMap<T> {
|
||||
index
|
||||
);
|
||||
|
||||
self.0[index] = value;
|
||||
self.0[index as usize] = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user