wip to fix

This commit is contained in:
Henri Bourcereau 2025-01-28 21:15:26 +01:00
parent 2a67996453
commit cabd3d9ab7
2 changed files with 41 additions and 13 deletions

View file

@ -41,7 +41,7 @@ lib
- can_take_corner_by_effect ok
- get_possible_moves_sequences -> cf. l.15
- check_exit_rules
- get_possible_moves_sequences -> cf l.15
- get_possible_moves_sequences(without exedents) -> cf l.15
- get_quarter_filling_moves_sequences
- get_possible_moves_sequences -> cf l.15
- state.consume (RollResult) (ok)

View file

@ -224,11 +224,21 @@ impl MoveRules {
}
// --- remplir cadran si possible & conserver cadran rempli si possible ----
if !ignored_rules.contains(&TricTracRule::MustFillQuarterRule) {
self.check_must_fill_quarter_rule(moves)?;
}
// no rule was broken
Ok(())
}
fn check_must_fill_quarter_rule(
&self,
moves: &(CheckerMove, CheckerMove),
) -> Result<(), MoveError> {
let filling_moves_sequences = self.get_quarter_filling_moves_sequences();
if !filling_moves_sequences.contains(moves) && !filling_moves_sequences.is_empty() {
return Err(MoveError::MustFillQuarter);
}
// no rule was broken
Ok(())
}
@ -284,7 +294,9 @@ impl MoveRules {
}
// toutes les sorties directes sont autorisées, ainsi que les nombres défaillants
let possible_moves_sequences_without_excedent = self.get_possible_moves_sequences(false);
let ignored_rules = vec![TricTracRule::ExitRule];
let possible_moves_sequences_without_excedent =
self.get_possible_moves_sequences(false, ignored_rules);
if possible_moves_sequences_without_excedent.contains(moves) {
return Ok(());
}
@ -337,6 +349,7 @@ impl MoveRules {
pub fn get_possible_moves_sequences(
&self,
with_excedents: bool,
ignored_rules: Vec<TricTracRule>,
) -> Vec<(CheckerMove, CheckerMove)> {
let (dice1, dice2) = self.dice.values;
let (dice_max, dice_min) = if dice1 > dice2 {
@ -344,8 +357,13 @@ impl MoveRules {
} else {
(dice2, dice1)
};
let mut moves_seqs =
self.get_possible_moves_sequences_by_dices(dice_max, dice_min, with_excedents, false);
let mut moves_seqs = self.get_possible_moves_sequences_by_dices(
dice_max,
dice_min,
with_excedents,
false,
ignored_rules,
);
// if we got valid sequences with the highest die, we don't accept sequences using only the
// lowest die
let ignore_empty = !moves_seqs.is_empty();
@ -354,6 +372,7 @@ impl MoveRules {
dice_max,
with_excedents,
ignore_empty,
ignored_rules,
);
moves_seqs.append(&mut moves_seqs_order2);
let empty_removed = moves_seqs
@ -418,7 +437,8 @@ impl MoveRules {
pub fn get_quarter_filling_moves_sequences(&self) -> Vec<(CheckerMove, CheckerMove)> {
let mut moves_seqs = Vec::new();
let color = &Color::White;
for moves in self.get_possible_moves_sequences(true) {
let ignored_rules = vec![TricTracRule::ExitRule, TricTracRule::MustFillQuarterRule];
for moves in self.get_possible_moves_sequences(true, ignored_rules) {
let mut board = self.board.clone();
board.move_checker(color, moves.0).unwrap();
board.move_checker(color, moves.1).unwrap();
@ -436,6 +456,7 @@ impl MoveRules {
dice2: u8,
with_excedents: bool,
ignore_empty: bool,
ignored_rules: Vec<TricTracRule>,
) -> Vec<(CheckerMove, CheckerMove)> {
let mut moves_seqs = Vec::new();
let color = &Color::White;
@ -459,22 +480,29 @@ impl MoveRules {
if self.check_corner_rules(&(first_move, second_move)).is_ok()
&& !(self.is_move_by_puissance(&(first_move, second_move))
&& self.can_take_corner_by_effect())
&& (ignored_rules.contains(&TricTracRule::ExitRule)
|| self.check_exit_rules(&(first_move, second_move)).is_ok())
&& (ignored_rules.contains(&TricTracRule::MustFillQuarterRule)
|| self
.check_must_fill_quarter_rule(&(first_move, second_move))
.is_ok())
{
moves_seqs.push((first_move, second_move));
has_second_dice_move = true;
}
// TODO : autres règles à vérifier (cf. moves_allowed)
// - check_exit_rules -> utilise get_possible_moves_sequences !
// - get_quarter_filling_moves_sequences -> utilise get_possible_moves_sequences !
}
if !has_second_dice_move
&& with_excedents
&& !ignore_empty
&& self.check_corner_rules(&(first_move, EMPTY_MOVE)).is_ok()
// TODO : autres règles à vérifier (cf. moves_allowed)
// - can_take_corner_by_effect
// - check_exit_rules
// - get_quarter_filling_moves_sequences
&& !(self.is_move_by_puissance(&(first_move, EMPTY_MOVE))
&& self.can_take_corner_by_effect())
&& (ignored_rules.contains(&TricTracRule::ExitRule)
|| self.check_exit_rules(&(first_move, EMPTY_MOVE)).is_ok())
&& (ignored_rules.contains(&TricTracRule::MustFillQuarterRule)
|| self
.check_must_fill_quarter_rule(&(first_move, EMPTY_MOVE))
.is_ok())
{
// empty move
moves_seqs.push((first_move, EMPTY_MOVE));