diff --git a/src/bitboard.rs b/src/bitboard.rs index afd0d32..6dd9330 100644 --- a/src/bitboard.rs +++ b/src/bitboard.rs @@ -10,19 +10,31 @@ impl BitBoard { BitBoard(0) } + const fn get_index(row: usize, col: usize) -> usize { + row * BOARD_SIZE + col + } + pub const fn get(&self, row: usize, col: usize) -> bool { - ((self.0 >> (row * BOARD_SIZE + col)) & 1) != 0 + ((self.0 >> Self::get_index(row, col)) & 1) != 0 } pub const fn set(&mut self, row: usize, col: usize, value: bool) { - let index = row * BOARD_SIZE + col; + let index = Self::get_index(row, col); if value { - self.0 |= 1 << index; // Set the bit at (row, col) to 1 + self.set_bit(index); // Set the bit at (row, col) to 1 } else { - self.0 &= !(1 << index); // Clear the bit at (row, col) + self.clear_bit(index); // Clear the bit at (row, col) } } + const fn clear_bit(&mut self, index: usize) { + self.0 &= !(1 << index) + } + + const fn set_bit(&mut self, index: usize) { + self.0 |= 1 << index + } + pub const fn count(&self) -> u32 { self.0.count_ones() }