moves allowed : check if opponent corner can be filled #2
This commit is contained in:
parent
84b5ab6a5f
commit
3c3c6d8458
3 changed files with 55 additions and 2 deletions
|
|
@ -456,9 +456,28 @@ impl GameState {
|
|||
}
|
||||
}
|
||||
|
||||
// --- interdit de jouer dans cadran que l'adversaire peut encore remplir ----
|
||||
let farthest = if *color == Color::White {
|
||||
cmp::max(moves.0.get_to(), moves.1.get_to())
|
||||
} else {
|
||||
cmp::min(moves.0.get_to(), moves.1.get_to())
|
||||
};
|
||||
let in_opponent_side = if *color == Color::White {
|
||||
farthest > 12
|
||||
} else {
|
||||
farthest < 13
|
||||
};
|
||||
|
||||
if in_opponent_side
|
||||
&& self
|
||||
.board
|
||||
.is_quarter_fillable(color.opponent_color(), farthest)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// --- remplir cadran si possible ----
|
||||
// --- conserver cadran rempli si possible ----
|
||||
// --- interdit de jouer dans cadran que l'adversaire peut encore remplir ----
|
||||
// no rule was broken
|
||||
true
|
||||
}
|
||||
|
|
@ -972,4 +991,28 @@ mod tests {
|
|||
assert!(state.moves_follows_dices(&Color::White, &moves));
|
||||
assert!(state.moves_allowed(&Color::White, &moves));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn move_check_fillable_quarter() {
|
||||
let mut state = GameState::default();
|
||||
state.board.set_positions([
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0,
|
||||
]);
|
||||
state.dice.values = (5, 5);
|
||||
let moves = (
|
||||
CheckerMove::new(11, 16).unwrap(),
|
||||
CheckerMove::new(11, 16).unwrap(),
|
||||
);
|
||||
assert!(state.moves_allowed(&Color::White, &moves));
|
||||
|
||||
state.board.set_positions([
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, -12, 0, 0, 0, 0, 1, 0,
|
||||
]);
|
||||
state.dice.values = (5, 5);
|
||||
let moves = (
|
||||
CheckerMove::new(11, 16).unwrap(),
|
||||
CheckerMove::new(11, 16).unwrap(),
|
||||
);
|
||||
assert!(!state.moves_allowed(&Color::White, &moves));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue