There are some bugs in the rewrite, need some elbow-grease to iron them out

main
Elijah C. Voigt 2 years ago
parent 3157666d84
commit 3d6ca40e67

@ -484,8 +484,8 @@ impl Board {
fn line(&self, from: BoardIndex, to: BoardIndex) -> impl Iterator<Item = BoardIndex> {
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

Loading…
Cancel
Save