Add more debug options & tweak difficulty settings
This commit is contained in:
parent
5c96f47765
commit
65c17741f9
2 changed files with 15 additions and 5 deletions
|
@ -56,6 +56,9 @@ impl Difficulty {
|
||||||
controller
|
controller
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note that we only need to check for minimum requirements because easier difficulities
|
||||||
|
// have turned off parts of the solver. For example, Difficulty::EASY cannot have any
|
||||||
|
// guesses simply by virtue of not allowing guesses during the generation process.
|
||||||
fn meets_minimum_requirements(&self, solve_statistics: &SolveStatistics) -> bool {
|
fn meets_minimum_requirements(&self, solve_statistics: &SolveStatistics) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Difficulty::Challenge => {
|
Difficulty::Challenge => {
|
||||||
|
@ -64,12 +67,12 @@ impl Difficulty {
|
||||||
&& (solve_statistics.useful_constraints > 20)
|
&& (solve_statistics.useful_constraints > 20)
|
||||||
}
|
}
|
||||||
Difficulty::Hard => {
|
Difficulty::Hard => {
|
||||||
(solve_statistics.possibility_groups > 20)
|
(solve_statistics.possibility_groups > 5)
|
||||||
&& (solve_statistics.useful_constraints > 20)
|
&& (solve_statistics.useful_constraints > 10)
|
||||||
}
|
}
|
||||||
Difficulty::Medium => {
|
Difficulty::Medium => {
|
||||||
(solve_statistics.possibility_groups > 10)
|
(solve_statistics.possibility_groups > 5)
|
||||||
&& (solve_statistics.useful_constraints > 10)
|
&& (solve_statistics.useful_constraints > 5)
|
||||||
}
|
}
|
||||||
Difficulty::Easy => true, // easy has no minimum
|
Difficulty::Easy => true, // easy has no minimum
|
||||||
}
|
}
|
||||||
|
@ -162,6 +165,7 @@ fn main() {
|
||||||
max_attempts,
|
max_attempts,
|
||||||
max_hints,
|
max_hints,
|
||||||
&AtomicBool::new(false),
|
&AtomicBool::new(false),
|
||||||
|
debug
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
run_multi_threaded(
|
run_multi_threaded(
|
||||||
|
@ -256,6 +260,7 @@ fn run_multi_threaded(
|
||||||
thread_attempts,
|
thread_attempts,
|
||||||
max_hints,
|
max_hints,
|
||||||
should_stop,
|
should_stop,
|
||||||
|
debug
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut result_was_some = false;
|
let mut result_was_some = false;
|
||||||
|
@ -308,6 +313,7 @@ fn get_puzzle_matching_conditions(
|
||||||
max_attempts: i32,
|
max_attempts: i32,
|
||||||
max_hints: i32,
|
max_hints: i32,
|
||||||
should_stop: &AtomicBool,
|
should_stop: &AtomicBool,
|
||||||
|
debug: bool
|
||||||
) -> (Option<(Grid, SolveStatistics, i32)>, i32) {
|
) -> (Option<(Grid, SolveStatistics, i32)>, i32) {
|
||||||
let mut num_attempts = 0;
|
let mut num_attempts = 0;
|
||||||
|
|
||||||
|
@ -316,6 +322,10 @@ fn get_puzzle_matching_conditions(
|
||||||
sudoku_solver::generator::generate_grid(rng, &solve_controller);
|
sudoku_solver::generator::generate_grid(rng, &solve_controller);
|
||||||
num_attempts += 1;
|
num_attempts += 1;
|
||||||
|
|
||||||
|
if debug {
|
||||||
|
println!("Found puzzle with {:#?}", solve_statistics);
|
||||||
|
}
|
||||||
|
|
||||||
if difficulty.meets_minimum_requirements(&solve_statistics) && num_hints <= max_hints {
|
if difficulty.meets_minimum_requirements(&solve_statistics) && num_hints <= max_hints {
|
||||||
return (Some((grid, solve_statistics, num_hints)), num_attempts);
|
return (Some((grid, solve_statistics, num_hints)), num_attempts);
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ impl SolveController {
|
||||||
/// that the method make at least one change to the line it was originally called on, whether that
|
/// that the method make at least one change to the line it was originally called on, whether that
|
||||||
/// be setting a value or adjusting the possibilities in a cell. Multiple contributions in one call
|
/// be setting a value or adjusting the possibilities in a cell. Multiple contributions in one call
|
||||||
/// of the strategy on a `Section` are only counted as one contribution.
|
/// of the strategy on a `Section` are only counted as one contribution.
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub struct SolveStatistics {
|
pub struct SolveStatistics {
|
||||||
pub singles: u32,
|
pub singles: u32,
|
||||||
pub hidden_singles: u32,
|
pub hidden_singles: u32,
|
||||||
|
|
Loading…
Reference in a new issue