refact(perf): remove Recursive get_possible_moves_sequences in check_must_fill_quarter_rule
This commit is contained in:
parent
44a5ba87b0
commit
45b9db61e3
1 changed files with 26 additions and 21 deletions
|
|
@ -441,12 +441,18 @@ impl MoveRules {
|
||||||
} else {
|
} else {
|
||||||
(dice2, dice1)
|
(dice2, dice1)
|
||||||
};
|
};
|
||||||
|
let filling_seqs = if !ignored_rules.contains(&TricTracRule::MustFillQuarter) {
|
||||||
|
Some(self.get_quarter_filling_moves_sequences())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
let mut moves_seqs = self.get_possible_moves_sequences_by_dices(
|
let mut moves_seqs = self.get_possible_moves_sequences_by_dices(
|
||||||
dice_max,
|
dice_max,
|
||||||
dice_min,
|
dice_min,
|
||||||
with_excedents,
|
with_excedents,
|
||||||
false,
|
false,
|
||||||
ignored_rules.clone(),
|
&ignored_rules,
|
||||||
|
filling_seqs.as_deref(),
|
||||||
);
|
);
|
||||||
// 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
|
||||||
|
|
@ -456,7 +462,8 @@ impl MoveRules {
|
||||||
dice_max,
|
dice_max,
|
||||||
with_excedents,
|
with_excedents,
|
||||||
ignore_empty,
|
ignore_empty,
|
||||||
ignored_rules,
|
&ignored_rules,
|
||||||
|
filling_seqs.as_deref(),
|
||||||
);
|
);
|
||||||
moves_seqs.append(&mut moves_seqs_order2);
|
moves_seqs.append(&mut moves_seqs_order2);
|
||||||
let empty_removed = moves_seqs
|
let empty_removed = moves_seqs
|
||||||
|
|
@ -545,7 +552,8 @@ impl MoveRules {
|
||||||
dice2: u8,
|
dice2: u8,
|
||||||
with_excedents: bool,
|
with_excedents: bool,
|
||||||
ignore_empty: bool,
|
ignore_empty: bool,
|
||||||
ignored_rules: Vec<TricTracRule>,
|
ignored_rules: &[TricTracRule],
|
||||||
|
filling_seqs: Option<&[(CheckerMove, CheckerMove)]>,
|
||||||
) -> 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;
|
||||||
|
|
@ -598,16 +606,8 @@ impl MoveRules {
|
||||||
// )
|
// )
|
||||||
// })
|
// })
|
||||||
.is_ok())
|
.is_ok())
|
||||||
&& (ignored_rules.contains(&TricTracRule::MustFillQuarter)
|
&& filling_seqs
|
||||||
|| self
|
.map_or(true, |seqs| seqs.is_empty() || seqs.contains(&(first_move, second_move)))
|
||||||
.check_must_fill_quarter_rule(&(first_move, second_move))
|
|
||||||
// .inspect_err(|e| {
|
|
||||||
// println!(
|
|
||||||
// " 2nd: {:?} - {:?}, {:?} for {:?}",
|
|
||||||
// e, first_move, second_move, self.board
|
|
||||||
// )
|
|
||||||
// })
|
|
||||||
.is_ok())
|
|
||||||
{
|
{
|
||||||
if second_move.get_to() == 0
|
if second_move.get_to() == 0
|
||||||
&& first_move.get_to() == 0
|
&& first_move.get_to() == 0
|
||||||
|
|
@ -631,10 +631,8 @@ impl MoveRules {
|
||||||
&& 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)).is_ok())
|
|| self.check_exit_rules(&(first_move, EMPTY_MOVE)).is_ok())
|
||||||
&& (ignored_rules.contains(&TricTracRule::MustFillQuarter)
|
&& filling_seqs
|
||||||
|| self
|
.map_or(true, |seqs| seqs.is_empty() || seqs.contains(&(first_move, EMPTY_MOVE)))
|
||||||
.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));
|
||||||
|
|
@ -1498,6 +1496,7 @@ mod tests {
|
||||||
CheckerMove::new(23, 0).unwrap(),
|
CheckerMove::new(23, 0).unwrap(),
|
||||||
CheckerMove::new(24, 0).unwrap(),
|
CheckerMove::new(24, 0).unwrap(),
|
||||||
);
|
);
|
||||||
|
let filling_seqs = Some(state.get_quarter_filling_moves_sequences());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
vec![moves],
|
vec![moves],
|
||||||
state.get_possible_moves_sequences_by_dices(
|
state.get_possible_moves_sequences_by_dices(
|
||||||
|
|
@ -1505,7 +1504,8 @@ mod tests {
|
||||||
state.dice.values.1,
|
state.dice.values.1,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
vec![]
|
&[],
|
||||||
|
filling_seqs.as_deref(),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -1520,6 +1520,7 @@ mod tests {
|
||||||
CheckerMove::new(19, 23).unwrap(),
|
CheckerMove::new(19, 23).unwrap(),
|
||||||
CheckerMove::new(22, 0).unwrap(),
|
CheckerMove::new(22, 0).unwrap(),
|
||||||
)];
|
)];
|
||||||
|
let filling_seqs = Some(state.get_quarter_filling_moves_sequences());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
moves,
|
moves,
|
||||||
state.get_possible_moves_sequences_by_dices(
|
state.get_possible_moves_sequences_by_dices(
|
||||||
|
|
@ -1527,7 +1528,8 @@ mod tests {
|
||||||
state.dice.values.1,
|
state.dice.values.1,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
vec![]
|
&[],
|
||||||
|
filling_seqs.as_deref(),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
let moves = vec![(
|
let moves = vec![(
|
||||||
|
|
@ -1541,7 +1543,8 @@ mod tests {
|
||||||
state.dice.values.0,
|
state.dice.values.0,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
vec![]
|
&[],
|
||||||
|
filling_seqs.as_deref(),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -1557,6 +1560,7 @@ mod tests {
|
||||||
CheckerMove::new(19, 21).unwrap(),
|
CheckerMove::new(19, 21).unwrap(),
|
||||||
CheckerMove::new(23, 0).unwrap(),
|
CheckerMove::new(23, 0).unwrap(),
|
||||||
);
|
);
|
||||||
|
let filling_seqs = Some(state.get_quarter_filling_moves_sequences());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
vec![moves],
|
vec![moves],
|
||||||
state.get_possible_moves_sequences_by_dices(
|
state.get_possible_moves_sequences_by_dices(
|
||||||
|
|
@ -1564,7 +1568,8 @@ mod tests {
|
||||||
state.dice.values.1,
|
state.dice.values.1,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
vec![]
|
&[],
|
||||||
|
filling_seqs.as_deref(),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue