|
|
|
@ -484,8 +484,8 @@ impl Board {
|
|
|
|
fn line(&self, from: BoardIndex, to: BoardIndex) -> impl Iterator<Item = BoardIndex> {
|
|
|
|
fn line(&self, from: BoardIndex, to: BoardIndex) -> impl Iterator<Item = BoardIndex> {
|
|
|
|
let mut curr = from;
|
|
|
|
let mut curr = from;
|
|
|
|
|
|
|
|
|
|
|
|
// Longest possible move is 10, so we create a generator over 11
|
|
|
|
// Longest possible move is 10, so we create a generator over 12
|
|
|
|
(0..11)
|
|
|
|
(0..12)
|
|
|
|
.map(move |_| {
|
|
|
|
.map(move |_| {
|
|
|
|
let x = if curr.x > to.x {
|
|
|
|
let x = if curr.x > to.x {
|
|
|
|
curr.x.saturating_sub(1)
|
|
|
|
curr.x.saturating_sub(1)
|
|
|
|
@ -534,7 +534,19 @@ impl Board {
|
|
|
|
// Cannot move on top of a friendly
|
|
|
|
// Cannot move on top of a friendly
|
|
|
|
Some(_) => Some(MoveType::Invalid),
|
|
|
|
Some(_) => Some(MoveType::Invalid),
|
|
|
|
// Any other spot is valid
|
|
|
|
// 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
|
|
|
|
// Check for moving across the canal
|
|
|
|
|