summaryrefslogtreecommitdiff
path: root/model/src/moves.rs
diff options
context:
space:
mode:
authorBotahamec <botahamec@outlook.com>2021-07-08 20:32:44 -0400
committerBotahamec <botahamec@outlook.com>2021-07-08 20:32:44 -0400
commit7e73782a7d51b40a558b74793c1d6c1abdea857d (patch)
treefba843de026f20cbcca0272c4ef521a6d4ac7ef9 /model/src/moves.rs
here's what i have so far
Diffstat (limited to 'model/src/moves.rs')
-rw-r--r--model/src/moves.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/model/src/moves.rs b/model/src/moves.rs
new file mode 100644
index 0000000..30024d6
--- /dev/null
+++ b/model/src/moves.rs
@@ -0,0 +1,59 @@
+use crate::CheckersBitBoard;
+
+#[derive(Copy, Clone, Eq, PartialEq)]
+pub enum MoveDirection {
+ ForwardLeft = 0,
+ ForwardRight = 1,
+ BackwardLeft = 2,
+ BackwardRight = 3,
+}
+
+#[derive(Copy, Clone)]
+pub struct Move {
+ start: u32,
+ direction: MoveDirection,
+ jump: bool,
+}
+
+impl Move {
+ pub const fn new(start: usize, direction: MoveDirection, jump: bool) -> Self {
+ Self {
+ start: start as u32,
+ direction,
+ jump,
+ }
+ }
+
+ pub const unsafe fn apply_to(self, board: CheckersBitBoard) -> CheckersBitBoard {
+ match self.jump {
+ false => match self.direction {
+ MoveDirection::ForwardLeft => {
+ board.move_piece_forward_left_unchecked(self.start as usize)
+ }
+ MoveDirection::ForwardRight => {
+ board.move_piece_forward_right_unchecked(self.start as usize)
+ }
+ MoveDirection::BackwardLeft => {
+ board.move_piece_backward_left_unchecked(self.start as usize)
+ }
+ MoveDirection::BackwardRight => {
+ board.move_piece_backward_right_unchecked(self.start as usize)
+ }
+ },
+ true => match self.direction {
+ MoveDirection::ForwardLeft => {
+ board.jump_piece_forward_left_unchecked(self.start as usize)
+ }
+ MoveDirection::ForwardRight => {
+ board.jump_piece_forward_right_unchecked(self.start as usize)
+ }
+ MoveDirection::BackwardLeft => {
+ board.jump_piece_backward_left_unchecked(self.start as usize)
+ }
+ MoveDirection::BackwardRight => {
+ board.jump_piece_backward_right_unchecked(self.start as usize)
+ }
+ },
+ }
+ }
+}