diff --git a/src/board.rs b/src/board.rs index ecbd2fd..a85524c 100644 --- a/src/board.rs +++ b/src/board.rs @@ -30,7 +30,14 @@ struct PosMap(ArrayVec); impl PosMap { 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 { "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`] let mut uniq = HashSet::new(); assert!( @@ -328,8 +335,8 @@ impl Board { /// Get the "net score" of a player /// Formula: `net_score = Score_player - Score_opponent` #[const_fn(cfg(not(feature = "bitvec")))] - pub const fn net_score(&self, piece: Piece) -> isize { - self.count(piece) as isize - self.count(piece.flip()) as isize + pub const fn net_score(&self, piece: Piece) -> i16 { + self.count(piece) as i16 - self.count(piece.flip()) as i16 } /// Returns the winner of the board (if any)