diff --git a/src/repr/bitboard.rs b/src/repr/bitboard.rs index fe0ed3f..289be4b 100644 --- a/src/repr/bitboard.rs +++ b/src/repr/bitboard.rs @@ -8,7 +8,7 @@ use static_assertions::const_assert; pub type BitBoardInner = u64; -#[derive(Copy, Clone, PartialEq, Eq, Allocative)] +#[derive(Copy, Clone, PartialEq, Eq, Allocative, Debug)] pub struct BitBoard(BitBoardInner); // BitBoard should be big enough to fit all points on the board @@ -24,14 +24,14 @@ impl BitBoard { 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 { ((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) { // PERF! branchless setting of bit (~+3% perf bump) self.0 &= !(0b1 << index); // clear bit @@ -133,4 +133,15 @@ mod test { b.set((2, 4).into(), false); 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) + ); + } }