From 369870509cf17f8bb7dcb73c497b7fb263685cfb Mon Sep 17 00:00:00 2001 From: Micha White Date: Thu, 21 Dec 2023 17:27:59 -0500 Subject: Added some small extra functionality to the engine --- model/src/moves.rs | 3 +++ model/src/possible_moves.rs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) (limited to 'model') diff --git a/model/src/moves.rs b/model/src/moves.rs index f6b1fce..720ded6 100644 --- a/model/src/moves.rs +++ b/model/src/moves.rs @@ -89,6 +89,9 @@ impl Move { /// This functions results in undefined behavior if: /// * The piece moves in a direction which would move it outside of the board /// * The starting position of this move doesn't contain a piece + /// * The end position already contains a piece + /// * A jump occurs where jumps are not allowed + /// * A move is not a jump even though jumps are available pub const unsafe fn apply_to(self, board: CheckersBitBoard) -> CheckersBitBoard { match self.jump { false => match self.direction { diff --git a/model/src/possible_moves.rs b/model/src/possible_moves.rs index 3dbc45b..0319d93 100644 --- a/model/src/possible_moves.rs +++ b/model/src/possible_moves.rs @@ -731,6 +731,22 @@ impl PossibleMoves { pub const fn can_jump(self) -> bool { (self.backward_right_movers & 2) != 0 } + + /// Returns true if the given move is possible + pub const fn contains(self, checker_move: Move) -> bool { + if checker_move.is_jump() != self.can_jump() { + return false; + } + + let bits = match checker_move.direction() { + MoveDirection::ForwardLeft => self.forward_left_movers, + MoveDirection::ForwardRight => self.forward_right_movers, + MoveDirection::BackwardLeft => self.backward_left_movers, + MoveDirection::BackwardRight => self.backward_right_movers, + }; + + (bits >> checker_move.start()) & 1 == 1 + } } #[cfg(test)] -- cgit v1.2.3