summaryrefslogtreecommitdiff
path: root/model/src/moves.rs
diff options
context:
space:
mode:
authorMike White <botahamec@outlook.com>2021-08-27 20:46:18 -0400
committerMike White <botahamec@outlook.com>2021-08-27 20:46:18 -0400
commita310274c6d5acea8f5f83f2feb8699e7b312f8e3 (patch)
tree9424e380512df43e64a50ad0824375d7f23b3c25 /model/src/moves.rs
parent68014734561c3a8d8712916bdfa58b8347131501 (diff)
Highlighted possible moves when a piece is clicked
Diffstat (limited to 'model/src/moves.rs')
-rw-r--r--model/src/moves.rs29
1 files changed, 26 insertions, 3 deletions
diff --git a/model/src/moves.rs b/model/src/moves.rs
index b8e58ee..7581b6b 100644
--- a/model/src/moves.rs
+++ b/model/src/moves.rs
@@ -38,6 +38,29 @@ impl Move {
}
}
+ pub const fn start(self) -> u32 {
+ self.start
+ }
+
+ /// Calculates the value of the end position of the 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,
+ },
+ true => match self.direction {
+ MoveDirection::ForwardLeft => self.start + 14,
+ MoveDirection::ForwardRight => self.start + 2,
+ MoveDirection::BackwardLeft => self.start - 2,
+ MoveDirection::BackwardRight => self.start - 14,
+ },
+ };
+ dest as usize
+ }
+
/// Apply the move to a board. This does not mutate the original board,
/// but instead returns a new one.
///
@@ -92,10 +115,10 @@ impl Move {
#[cfg(test)]
mod tests {
- use proptest::prelude::*;
use super::*;
+ use proptest::prelude::*;
- proptest!{
+ proptest! {
#[test]
fn new(start in 0usize..32, jump in proptest::bool::ANY) {
let direction = MoveDirection::ForwardLeft;
@@ -123,4 +146,4 @@ mod tests {
assert_eq!(move_test.jump, jump);
}
}
-} \ No newline at end of file
+}