fix(store): check_opponent_can_fill_quarter_rule on both checkers
This commit is contained in:
parent
7e8d0a18c1
commit
43196bcef8
2 changed files with 32 additions and 4 deletions
|
|
@ -574,7 +574,6 @@ mod tests {
|
||||||
dice,
|
dice,
|
||||||
dice_jans: Vec::new(),
|
dice_jans: Vec::new(),
|
||||||
dice_moves: (CheckerMove::default(), CheckerMove::default()),
|
dice_moves: (CheckerMove::default(), CheckerMove::default()),
|
||||||
message: "".into(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -257,11 +257,24 @@ impl MoveRules {
|
||||||
&self,
|
&self,
|
||||||
moves: &(CheckerMove, CheckerMove),
|
moves: &(CheckerMove, CheckerMove),
|
||||||
) -> Result<(), MoveError> {
|
) -> Result<(), MoveError> {
|
||||||
let farthest = cmp::max(moves.0.get_to(), moves.1.get_to());
|
// A chained move (tout d'une): the first destination is a resting field.
|
||||||
let in_opponent_side = farthest > 12;
|
// Exception: a resting field in the opponent's big jan (13-18) is allowed
|
||||||
if in_opponent_side && self.board.is_quarter_fillable(Color::Black, farthest) {
|
// during a chained move to pass into the return jan.
|
||||||
|
let is_chained =
|
||||||
|
moves.1.get_from() != 0 && moves.0.get_to() == moves.1.get_from();
|
||||||
|
|
||||||
|
if !is_chained {
|
||||||
|
let to0 = moves.0.get_to();
|
||||||
|
if to0 > 12 && self.board.is_quarter_fillable(Color::Black, to0) {
|
||||||
return Err(MoveError::OpponentCanFillQuarter);
|
return Err(MoveError::OpponentCanFillQuarter);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let to1 = moves.1.get_to();
|
||||||
|
if to1 > 12 && self.board.is_quarter_fillable(Color::Black, to1) {
|
||||||
|
return Err(MoveError::OpponentCanFillQuarter);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -970,6 +983,22 @@ mod tests {
|
||||||
state.moves_allowed(&moves)
|
state.moves_allowed(&moves)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
state.board.set_positions(
|
||||||
|
&Color::Black,
|
||||||
|
[
|
||||||
|
0, 0, 0, 0, -1, 1, 3, 0, 3, 4, 1, 3, 0, -2, -5, -2, -1, -4, 0, 0, 0, 0, 0, 0,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
state.dice.values = (6, 2);
|
||||||
|
let moves = (
|
||||||
|
CheckerMove::new(14, 8).unwrap().mirror(),
|
||||||
|
CheckerMove::new(5, 3).unwrap().mirror(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
Err(MoveError::OpponentCanFillQuarter),
|
||||||
|
state.moves_allowed(&moves)
|
||||||
|
);
|
||||||
|
|
||||||
state.board.set_positions(
|
state.board.set_positions(
|
||||||
&Color::White,
|
&Color::White,
|
||||||
[
|
[
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue