diff --git a/doc/refs/journal.md b/doc/refs/journal.md index 75b028a..2b4a064 100644 --- a/doc/refs/journal.md +++ b/doc/refs/journal.md @@ -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) diff --git a/store/src/game_rules_moves.rs b/store/src/game_rules_moves.rs index a68d8a0..deabf04 100644 --- a/store/src/game_rules_moves.rs +++ b/store/src/game_rules_moves.rs @@ -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, ) -> 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, ) -> 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));