summaryrefslogtreecommitdiff
path: root/model/src/moves.rs
diff options
context:
space:
mode:
authorMike White <botahamec@outlook.com>2021-08-29 17:59:40 -0400
committerMike White <botahamec@outlook.com>2021-08-29 17:59:40 -0400
commit8388d471c339e73126532198579b2fd9c67dbae2 (patch)
treea3d2afd6a60e4c832c830ad290127087967521f5 /model/src/moves.rs
parenta310274c6d5acea8f5f83f2feb8699e7b312f8e3 (diff)
Added the ability to move
Diffstat (limited to 'model/src/moves.rs')
-rw-r--r--model/src/moves.rs20
1 files changed, 10 insertions, 10 deletions
diff --git a/model/src/moves.rs b/model/src/moves.rs
index 7581b6b..12a26db 100644
--- a/model/src/moves.rs
+++ b/model/src/moves.rs
@@ -1,6 +1,6 @@
use crate::CheckersBitBoard;
-#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum MoveDirection {
ForwardLeft = 0,
ForwardRight = 1,
@@ -9,7 +9,7 @@ pub enum MoveDirection {
}
/// A checkers move
-#[derive(Copy, Clone, Debug)]
+#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct Move {
/// The position of the piece to move
start: u32,
@@ -46,16 +46,16 @@ impl Move {
pub const fn end_position(self) -> usize {
let dest = match self.jump {
false => match self.direction {
- MoveDirection::ForwardLeft => self.start + 7,
- MoveDirection::ForwardRight => self.start + 1,
- MoveDirection::BackwardLeft => self.start - 1,
- MoveDirection::BackwardRight => self.start - 7,
+ MoveDirection::ForwardLeft => (self.start + 7) % 32,
+ MoveDirection::ForwardRight => (self.start + 1) % 32,
+ MoveDirection::BackwardLeft => self.start.wrapping_sub(1) % 32,
+ MoveDirection::BackwardRight => self.start.wrapping_sub(7) % 32,
},
true => match self.direction {
- MoveDirection::ForwardLeft => self.start + 14,
- MoveDirection::ForwardRight => self.start + 2,
- MoveDirection::BackwardLeft => self.start - 2,
- MoveDirection::BackwardRight => self.start - 14,
+ MoveDirection::ForwardLeft => (self.start + 14) % 32,
+ MoveDirection::ForwardRight => (self.start + 2) % 32,
+ MoveDirection::BackwardLeft => self.start.wrapping_sub(2) % 32,
+ MoveDirection::BackwardRight => self.start.wrapping_sub(14) % 32,
},
};
dest as usize