bitboard: add test for compounding directions
This commit is contained in:
parent
c0eac2b175
commit
680a2d084c
@ -8,7 +8,7 @@ use static_assertions::const_assert;
|
|||||||
|
|
||||||
pub type BitBoardInner = u64;
|
pub type BitBoardInner = u64;
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Allocative)]
|
#[derive(Copy, Clone, PartialEq, Eq, Allocative, Debug)]
|
||||||
pub struct BitBoard(BitBoardInner);
|
pub struct BitBoard(BitBoardInner);
|
||||||
|
|
||||||
// BitBoard should be big enough to fit all points on the board
|
// BitBoard should be big enough to fit all points on the board
|
||||||
@ -24,14 +24,14 @@ impl BitBoard {
|
|||||||
self.get_by_index(coord.0)
|
self.get_by_index(coord.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn set(&mut self, coord: CoordPair, value: bool) {
|
|
||||||
self.set_by_index(coord.0, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
const fn get_by_index(&self, index: CoordPairInner) -> bool {
|
const fn get_by_index(&self, index: CoordPairInner) -> bool {
|
||||||
((self.0 >> index) & 0b1) != 0b0
|
((self.0 >> index) & 0b1) != 0b0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const fn set(&mut self, coord: CoordPair, value: bool) {
|
||||||
|
self.set_by_index(coord.0, value);
|
||||||
|
}
|
||||||
|
|
||||||
const fn set_by_index(&mut self, index: CoordPairInner, value: bool) {
|
const fn set_by_index(&mut self, index: CoordPairInner, value: bool) {
|
||||||
// PERF! branchless setting of bit (~+3% perf bump)
|
// PERF! branchless setting of bit (~+3% perf bump)
|
||||||
self.0 &= !(0b1 << index); // clear bit
|
self.0 &= !(0b1 << index); // clear bit
|
||||||
@ -133,4 +133,15 @@ 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)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user