summaryrefslogtreecommitdiff
path: root/model/src
diff options
context:
space:
mode:
Diffstat (limited to 'model/src')
-rw-r--r--model/src/moves.rs3
-rw-r--r--model/src/possible_moves.rs16
2 files changed, 19 insertions, 0 deletions
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)]