bitboard: remove unused multi shift

This commit is contained in:
Simon Gardling 2025-03-17 13:55:46 -04:00
parent 680a2d084c
commit 77bf0e6438
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D
2 changed files with 17 additions and 28 deletions

View File

@ -46,38 +46,38 @@ impl BitBoard {
self.0 == 0b0 self.0 == 0b0
} }
pub const fn east(&self, n: usize) -> Self { pub const fn east(&self) -> Self {
let mask = !Self::col_mask(Board::SIZE - 1).0; // Mask to block column BOARD_SIZE-1 bits let mask = !Self::col_mask(Board::SIZE - 1).0; // Mask to block column BOARD_SIZE-1 bits
Self((self.0 & mask) << n) Self((self.0 & mask) << 1)
} }
pub const fn west(&self, n: usize) -> Self { pub const fn west(&self) -> Self {
let mask = !Self::col_mask(0).0; let mask = !Self::col_mask(0).0;
Self((self.0 & mask) >> n) Self((self.0 & mask) >> 1)
} }
pub const fn north(&self, n: usize) -> Self { pub const fn north(&self) -> Self {
Self(self.0 >> (Board::SIZE as usize * n)) Self(self.0 >> Board::SIZE)
} }
pub const fn south(&self, n: usize) -> Self { pub const fn south(&self) -> Self {
Self(self.0 << (Board::SIZE as usize * n)) Self(self.0 << Board::SIZE)
} }
pub const fn northeast(&self, n: usize) -> Self { pub const fn northeast(&self) -> Self {
self.north(n).east(n) self.north().east()
} }
pub const fn northwest(&self, n: usize) -> Self { pub const fn northwest(&self) -> Self {
self.north(n).west(n) self.north().west()
} }
pub const fn southeast(&self, n: usize) -> Self { pub const fn southeast(&self) -> Self {
self.south(n).east(n) self.south().east()
} }
pub const fn southwest(&self, n: usize) -> Self { pub const fn southwest(&self) -> Self {
self.south(n).west(n) self.south().west()
} }
// Mask for a specific column (e.g., col_mask(7) = 0x8080808080808080) // Mask for a specific column (e.g., col_mask(7) = 0x8080808080808080)
@ -133,15 +133,4 @@ mod test {
b.set((2, 4).into(), false); b.set((2, 4).into(), false);
assert!(!b.get((2, 4).into())); assert!(!b.get((2, 4).into()));
} }
#[test]
fn dir_multi() {
let mut base = BitBoard::from_coord(CoordPair::from_axes(4, 4));
base = base.southeast(1);
base = base.southeast(1);
assert_eq!(
base,
BitBoard::from_coord(CoordPair::from_axes(4, 4)).southeast(2)
);
}
} }

View File

@ -294,7 +294,7 @@ impl Board {
// PERF! tested unrolling this loop using `const_for` // PERF! tested unrolling this loop using `const_for`
// resulted in a 9% slowdown // resulted in a 9% slowdown
loop { loop {
current = $dir(&current, 1); current = $dir(&current);
if current.is_empty() || !current.intersects(*opponent_board) { if current.is_empty() || !current.intersects(*opponent_board) {
break; break;
} }