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