This repository has been archived on 2026-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
worldulu/src/solver.rs

62 lines
2.1 KiB
Rust

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,
number_depth: NumberDepth,
guess_depth: GuessDepth,
) -> word_representation::TotalScore {
if *number_depth == 0 {
word_representation::TotalScore::default()
} else {
// println!("Starts new track: TS[{:?}]", &total_score);
// Sort original data
let mut list = origin_list.clone();
let weights = origin_weights.clone();
list.update_weights(&weights);
list.sort();
// 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 {
let guess = list.guess(i);
// println!("Guess: {:?}", guess);
let mut weights = origin_weights.clone();
weights.remove_word(&guess);
// Backtrack the implied scores
let bb = backtrack_best(
&list,
&weights,
total_score.clone(),
number_depth.decrement(),
guess_depth,
);
let mut v = bb.words.clone();
v.push(guess.clone());
list_guesses.push(word_representation::TotalScore {
score: bb.score + guess.weight,
words: v,
});
}
list_guesses.sort();
// println!("List guesses {:#?}", list_guesses);
let best_implied_score = list_guesses.last().unwrap().clone();
// println!("best impl: {:?}", best_implied_score);
total_score.add(best_implied_score);
// println!("best added: {:?}", total_score);
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!()
}