More rework
This commit is contained in:
parent
81cbca8783
commit
b486a027c9
|
|
@ -78,7 +78,13 @@ fn dispatch_calculate(
|
|||
println!(
|
||||
"Best {}: {:#?}",
|
||||
number,
|
||||
backtrack_best(&wl, &weights, TotalScore::default(), number, depth)
|
||||
backtrack_best(
|
||||
&wl,
|
||||
&weights,
|
||||
TotalScore::default(),
|
||||
word_representation::NumberDepth::new(number),
|
||||
word_representation::GuessDepth::new(depth)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
use crate::word_representation;
|
||||
use crate::word_representation::{self, GuessDepth, NumberDepth};
|
||||
|
||||
pub(crate) fn backtrack_best(
|
||||
origin_list: &word_representation::Wordlist,
|
||||
origin_weights: &word_representation::Weightlist,
|
||||
mut total_score: word_representation::TotalScore,
|
||||
letter_depth: usize,
|
||||
guess_depth: usize,
|
||||
number_depth: NumberDepth,
|
||||
guess_depth: GuessDepth,
|
||||
) -> word_representation::TotalScore {
|
||||
if letter_depth == 0 {
|
||||
if *number_depth == 0 {
|
||||
word_representation::TotalScore::default()
|
||||
} else {
|
||||
// println!("Starts new track: TS[{:?}]", &total_score);
|
||||
|
|
@ -19,7 +19,7 @@ pub(crate) fn backtrack_best(
|
|||
|
||||
// Pick n bests word, backtrack their score and return the best of the best results
|
||||
let mut list_guesses = Vec::new();
|
||||
for i in 0..guess_depth {
|
||||
for i in 0..*guess_depth {
|
||||
let guess = list.guess(i);
|
||||
// println!("Guess: {:?}", guess);
|
||||
let mut weights = origin_weights.clone();
|
||||
|
|
@ -29,7 +29,7 @@ pub(crate) fn backtrack_best(
|
|||
&list,
|
||||
&weights,
|
||||
total_score.clone(),
|
||||
letter_depth - 1,
|
||||
number_depth.decrement(),
|
||||
guess_depth,
|
||||
);
|
||||
let mut v = bb.words.clone();
|
||||
|
|
@ -48,3 +48,14 @@ pub(crate) fn backtrack_best(
|
|||
total_score
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a list of best word combinations
|
||||
#[allow(unused_variables, dead_code)]
|
||||
pub(crate) fn create_list_best(
|
||||
origin_list: &word_representation::Wordlist,
|
||||
origin_weights: &word_representation::Weightlist,
|
||||
letter_depth: usize,
|
||||
guess_depth: usize,
|
||||
) -> word_representation::TotalScore {
|
||||
todo!()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,6 +90,14 @@ pub(crate) struct Wordlist {
|
|||
pub(crate) inner: Vec<Word>,
|
||||
}
|
||||
|
||||
impl std::ops::Deref for Wordlist {
|
||||
type Target = Vec<Word>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Wordlist {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let o = self
|
||||
|
|
@ -167,3 +175,47 @@ impl PartialOrd for TotalScore {
|
|||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
/// The number of different combinations to try
|
||||
#[derive(Clone, Copy)]
|
||||
pub(crate) struct GuessDepth {
|
||||
n: usize,
|
||||
}
|
||||
|
||||
impl GuessDepth {
|
||||
pub(crate) fn new(n: usize) -> Self {
|
||||
Self { n }
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Deref for GuessDepth {
|
||||
type Target = usize;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.n
|
||||
}
|
||||
}
|
||||
|
||||
/// The number of words to generate in the solution
|
||||
#[derive(Clone, Copy)]
|
||||
pub(crate) struct NumberDepth {
|
||||
n: usize,
|
||||
}
|
||||
impl NumberDepth {
|
||||
pub(crate) fn new(n: usize) -> Self {
|
||||
Self { n }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn decrement(&self) -> NumberDepth {
|
||||
NumberDepth::new(self.n - 1)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Deref for NumberDepth {
|
||||
type Target = usize;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.n
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in New Issue