From 3d6ca40e6725551bf965309c8c380a52bbd9bd78 Mon Sep 17 00:00:00 2001 From: "Elijah C. Voigt" Date: Mon, 1 Apr 2024 23:12:49 -0700 Subject: [PATCH] There are some bugs in the rewrite, need some elbow-grease to iron them out --- src/game.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/game.rs b/src/game.rs index 456e944..e684567 100644 --- a/src/game.rs +++ b/src/game.rs @@ -484,8 +484,8 @@ impl Board { fn line(&self, from: BoardIndex, to: BoardIndex) -> impl Iterator { let mut curr = from; - // Longest possible move is 10, so we create a generator over 11 - (0..11) + // Longest possible move is 10, so we create a generator over 12 + (0..12) .map(move |_| { let x = if curr.x > to.x { curr.x.saturating_sub(1) @@ -534,7 +534,19 @@ impl Board { // Cannot move on top of a friendly Some(_) => Some(MoveType::Invalid), // Any other spot is valid - None => Some(MoveType::Valid), + None => { + // If there is another piece between A and B + if self + .line(from, to) + .any(|board_index| self.at(board_index).is_some()) + { + // Invalid move, there is a piece between A and B + Some(MoveType::Invalid) + } else { + // Otherwise it's a valid + Some(MoveType::Valid) + } + } } } // Check for moving across the canal