From 445f94daf06a71f7be355d08e02ea9665f62aa17 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Tue, 4 Mar 2025 14:10:17 -0500 Subject: [PATCH] fix shift --- src/repr/bitboard.rs | 5 +++-- src/repr/board.rs | 7 +++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/repr/bitboard.rs b/src/repr/bitboard.rs index ee22f00..3e9a359 100644 --- a/src/repr/bitboard.rs +++ b/src/repr/bitboard.rs @@ -3,6 +3,7 @@ use super::{ coords::{CoordPair, CoordPairInner}, CoordAxis, }; +use num::PrimInt; use static_assertions::const_assert; #[cfg(not(feature = "bitvec"))] @@ -45,7 +46,7 @@ impl BitBoard { // Directional shifts with edge masking (prevents wrapping) pub const fn east(&self) -> Self { - let mask = !Self::col_mask(Board::BOARD_SIZE).0; // Mask to block column 7 bits + let mask = !Self::col_mask(Board::BOARD_SIZE - 1).0; // Mask to block column 7 bits Self((self.0 & mask) << 1) } @@ -100,7 +101,7 @@ impl BitBoard { } pub fn intersects(self, other: Self) -> bool { - (self & other).count() > 0 + (self.0 & other.0) > 0 } pub fn union(self, other: Self) -> Self { diff --git a/src/repr/board.rs b/src/repr/board.rs index cbef688..9735980 100644 --- a/src/repr/board.rs +++ b/src/repr/board.rs @@ -271,9 +271,8 @@ impl Board { /// DO NOT USE THIS ALONE, this should be called as a part of /// [`Board::place`] or [`Board::place_and_prop_unchecked`] fn propegate_from_dry(&self, coords: CoordPair, starting_color: Piece) -> BitBoard { - let opponent_color = starting_color.flip(); let player_board = *self.board(starting_color); - let opponent_board = *self.board(opponent_color); + let opponent_board = *self.board(starting_color.flip()); let mut flip_mask = BitBoard::new(); let seed = BitBoard::from_coord(coords); @@ -300,12 +299,12 @@ impl Board { if current.count() == 0 || !current.intersects(opponent_board) { break; } - temp_flips = temp_flips.union(current); + temp_flips |= current; } // If terminated on a player piece, keep the flips if current.intersects(player_board) { - flip_mask = flip_mask.union(temp_flips); + flip_mask |= temp_flips; } }