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