board fixups
This commit is contained in:
parent
c2120dfcc4
commit
846dfc8b4c
15
src/board.rs
15
src/board.rs
@ -30,7 +30,14 @@ struct PosMap<T>(ArrayVec<T, BOARD_AREA>);
|
|||||||
|
|
||||||
impl<T> PosMap<T> {
|
impl<T> PosMap<T> {
|
||||||
pub fn get(&self, row: usize, col: usize) -> &T {
|
pub fn get(&self, row: usize, col: usize) -> &T {
|
||||||
&self.0[row * BOARD_SIZE + col]
|
let index = row * BOARD_SIZE + col;
|
||||||
|
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
if index > BOARD_AREA + 1 {
|
||||||
|
panic!("index is out of range");
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe { &self.0.get_unchecked(index) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +79,7 @@ fn gen_adj_lookup() -> PosMap<ChainCollection> {
|
|||||||
"chains go out-of-bounds"
|
"chains go out-of-bounds"
|
||||||
);
|
);
|
||||||
|
|
||||||
// ensure all nodes in all chains are unique across chains, ensures beavior in
|
// SAFETY! ensure all nodes in all chains are unique across chains, ensures beavior in
|
||||||
// [`Board::propegate_from`]
|
// [`Board::propegate_from`]
|
||||||
let mut uniq = HashSet::new();
|
let mut uniq = HashSet::new();
|
||||||
assert!(
|
assert!(
|
||||||
@ -328,8 +335,8 @@ impl Board {
|
|||||||
/// Get the "net score" of a player
|
/// Get the "net score" of a player
|
||||||
/// Formula: `net_score = Score_player - Score_opponent`
|
/// Formula: `net_score = Score_player - Score_opponent`
|
||||||
#[const_fn(cfg(not(feature = "bitvec")))]
|
#[const_fn(cfg(not(feature = "bitvec")))]
|
||||||
pub const fn net_score(&self, piece: Piece) -> isize {
|
pub const fn net_score(&self, piece: Piece) -> i16 {
|
||||||
self.count(piece) as isize - self.count(piece.flip()) as isize
|
self.count(piece) as i16 - self.count(piece.flip()) as i16
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the winner of the board (if any)
|
/// Returns the winner of the board (if any)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user