summaryrefslogtreecommitdiff
path: root/model/src/possible_moves.rs
diff options
context:
space:
mode:
authorMicha White <botahamec@outlook.com>2023-12-29 00:05:43 -0500
committerMicha White <botahamec@outlook.com>2023-12-29 00:05:43 -0500
commit93461aa9399d981db7d8611b3eb166636de4d971 (patch)
tree729f46ce3ca70c13e4fd685c764afd1837e7d400 /model/src/possible_moves.rs
parenta3794530958ccd8bc6d8a7ed90edf3d1fd91bc54 (diff)
BIG BUG: board didn't require double jumps to use same piece
Diffstat (limited to 'model/src/possible_moves.rs')
-rw-r--r--model/src/possible_moves.rs27
1 files changed, 19 insertions, 8 deletions
diff --git a/model/src/possible_moves.rs b/model/src/possible_moves.rs
index bf69df6..ef05048 100644
--- a/model/src/possible_moves.rs
+++ b/model/src/possible_moves.rs
@@ -699,10 +699,26 @@ impl PossibleMoves {
}
}
- pub const fn moves(board: CheckersBitBoard) -> Self {
- match board.turn() {
+ const fn filter_to_square(self, square: u8) -> Self {
+ let mask = 1 << square;
+ Self {
+ forward_left_movers: self.forward_left_movers & mask,
+ forward_right_movers: self.forward_right_movers & mask,
+ backward_left_movers: self.backward_left_movers & mask,
+ backward_right_movers: self.backward_right_movers & (mask | 2),
+ }
+ }
+
+ pub fn moves(board: CheckersBitBoard) -> Self {
+ let moves = match board.turn() {
PieceColor::Dark => Self::dark_moves(board),
PieceColor::Light => Self::light_moves(board),
+ };
+
+ if board.turn == board.previous_turn {
+ moves.filter_to_square(board.previous_move_to)
+ } else {
+ moves
}
}
@@ -1026,12 +1042,7 @@ mod tests {
//second bit while there is no piece in the 26th bit. If you don't
// apply the bit mask for collision detection, then all of the light
// player moves become jumps.
- let board = CheckersBitBoard {
- pieces: 16908890,
- color: 401395713,
- kings: 50332352,
- turn: PieceColor::Light,
- };
+ let board = CheckersBitBoard::new(16908890, 401395713, 50332352, PieceColor::Light);
let possible_moves = PossibleMoves::moves(board);
assert!(!possible_moves.can_jump())
}