fix(store): allow tout d'une on rest corner move rules

This commit is contained in:
Henri Bourcereau 2026-03-29 21:14:16 +02:00
parent e414e28047
commit 9980fe70f2

View file

@ -297,7 +297,11 @@ impl MoveRules {
} }
// the last 2 checkers of a corner must leave at the same time // the last 2 checkers of a corner must leave at the same time
if (from0 == corner_field || from1 == corner_field) && (from0 != from1) && corner_count == 2 if (from0 == corner_field || from1 == corner_field)
&& (from0 != from1)
&& corner_count == 2
&& to0 != corner_field
&& to1 != corner_field
{ {
return Err(MoveError::CornerNeedsTwoCheckers); return Err(MoveError::CornerNeedsTwoCheckers);
} }
@ -339,8 +343,7 @@ impl MoveRules {
let seqs = match exit_seqs { let seqs = match exit_seqs {
Some(s) => s, Some(s) => s,
None => { None => {
owned = self owned = self.get_possible_moves_sequences(false, vec![TricTracRule::Exit]);
.get_possible_moves_sequences(false, vec![TricTracRule::Exit]);
&owned &owned
} }
}; };
@ -620,8 +623,9 @@ impl MoveRules {
|| self || self
.check_exit_rules(&(first_move, second_move), exit_seqs.as_deref()) .check_exit_rules(&(first_move, second_move), exit_seqs.as_deref())
.is_ok()) .is_ok())
&& filling_seqs && filling_seqs.map_or(true, |seqs| {
.map_or(true, |seqs| seqs.is_empty() || seqs.contains(&(first_move, second_move))) seqs.is_empty() || seqs.contains(&(first_move, second_move))
})
{ {
if second_move.get_to() == 0 if second_move.get_to() == 0
&& first_move.get_to() == 0 && first_move.get_to() == 0
@ -644,9 +648,12 @@ impl MoveRules {
&& !(self.is_move_by_puissance(&(first_move, EMPTY_MOVE)) && !(self.is_move_by_puissance(&(first_move, EMPTY_MOVE))
&& self.can_take_corner_by_effect()) && self.can_take_corner_by_effect())
&& (ignored_rules.contains(&TricTracRule::Exit) && (ignored_rules.contains(&TricTracRule::Exit)
|| self.check_exit_rules(&(first_move, EMPTY_MOVE), exit_seqs.as_deref()).is_ok()) || self
&& filling_seqs .check_exit_rules(&(first_move, EMPTY_MOVE), exit_seqs.as_deref())
.map_or(true, |seqs| seqs.is_empty() || seqs.contains(&(first_move, EMPTY_MOVE))) .is_ok())
&& filling_seqs.map_or(true, |seqs| {
seqs.is_empty() || seqs.contains(&(first_move, EMPTY_MOVE))
})
{ {
// empty move // empty move
moves_seqs.push((first_move, EMPTY_MOVE)); moves_seqs.push((first_move, EMPTY_MOVE));
@ -1640,4 +1647,21 @@ mod tests {
); );
assert!(state.check_must_fill_quarter_rule(&moves).is_ok()); assert!(state.check_must_fill_quarter_rule(&moves).is_ok());
} }
#[test]
fn check_rest_on_rest_corner() {
let mut state = MoveRules::default();
state.dice.values = (4, 1);
state.board.set_positions(
&crate::Color::White,
[
0, 0, -1, -4, -2, -1, 0, -2, -2, 4, 3, 2, 0, -1, -2, 0, 0, 1, 0, 1, 1, 1, 0, 2,
],
);
let moves = (
CheckerMove::new(11, 12).unwrap(),
CheckerMove::new(12, 16).unwrap(),
);
state.moves_allowed(&moves).expect("moves_allowed failed");
}
} }