bitboard: make directional methods take step argument
This commit is contained in:
parent
a0cd9edc32
commit
72dc7b9a48
@ -45,43 +45,42 @@ impl BitBoard {
|
||||
self.0 == 0
|
||||
}
|
||||
|
||||
// Directional shifts with edge masking (prevents wrapping)
|
||||
pub const fn east(&self) -> Self {
|
||||
let mask = !Self::col_mask(Board::BOARD_SIZE - 1).0; // Mask to block column 7 bits
|
||||
Self((self.0 & mask) << 1)
|
||||
pub const fn east(&self, n: usize) -> Self {
|
||||
let mask = !Self::col_mask(Board::BOARD_SIZE - 1).0; // Mask to block column BOARD_SIZE-1 bits
|
||||
Self((self.0 & mask) << n)
|
||||
}
|
||||
|
||||
pub const fn west(&self) -> Self {
|
||||
pub const fn west(&self, n: usize) -> Self {
|
||||
let mask = !Self::col_mask(0).0;
|
||||
Self((self.0 & mask) >> 1)
|
||||
Self((self.0 & mask) >> n)
|
||||
}
|
||||
|
||||
pub const fn north(&self) -> Self {
|
||||
Self(self.0 >> Board::BOARD_SIZE)
|
||||
pub const fn north(&self, n: usize) -> Self {
|
||||
Self(self.0 >> (Board::BOARD_SIZE as usize * n))
|
||||
}
|
||||
|
||||
pub const fn south(&self) -> Self {
|
||||
Self(self.0 << Board::BOARD_SIZE)
|
||||
pub const fn south(&self, n: usize) -> Self {
|
||||
Self(self.0 << (Board::BOARD_SIZE as usize * n))
|
||||
}
|
||||
|
||||
pub const fn northeast(&self) -> Self {
|
||||
self.north().east()
|
||||
pub const fn northeast(&self, n: usize) -> Self {
|
||||
self.north(n).east(n)
|
||||
}
|
||||
|
||||
pub const fn northwest(&self) -> Self {
|
||||
self.north().west()
|
||||
pub const fn northwest(&self, n: usize) -> Self {
|
||||
self.north(n).west(n)
|
||||
}
|
||||
|
||||
pub const fn southeast(&self) -> Self {
|
||||
self.south().east()
|
||||
pub const fn southeast(&self, n: usize) -> Self {
|
||||
self.south(n).east(n)
|
||||
}
|
||||
|
||||
pub const fn southwest(&self) -> Self {
|
||||
self.south().west()
|
||||
pub const fn southwest(&self, n: usize) -> Self {
|
||||
self.south(n).west(n)
|
||||
}
|
||||
|
||||
/// All direction methods
|
||||
pub const DIRECTIONS: [fn(&Self) -> Self; 8] = [
|
||||
pub const DIRECTIONS: [fn(&Self, usize) -> Self; 8] = [
|
||||
BitBoard::east,
|
||||
BitBoard::west,
|
||||
BitBoard::north,
|
||||
|
||||
@ -298,7 +298,7 @@ impl Board {
|
||||
|
||||
// Expand in direction until edge or non-opponent piece
|
||||
loop {
|
||||
current = dir(¤t);
|
||||
current = dir(¤t, 1);
|
||||
if current.is_empty() || !current.intersects(*opponent_board) {
|
||||
break;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user