add panic if solution space is empty

This commit is contained in:
2026-08-18 20:33:26 +02:00
parent 992890ebb2
commit 416ab6beba
2 changed files with 7 additions and 1 deletions
+3 -1
View File
@@ -5,7 +5,9 @@ use wordle_solver::{game::Game, solver::Solver, word_list::WordList};
pub fn main() { pub fn main() {
let valid_words = WordList::from_file(Path::new("valid-words.txt")).unwrap(); let valid_words = WordList::from_file(Path::new("valid-words.txt")).unwrap();
let target_words = WordList::from_file(Path::new("answers.txt")).unwrap(); let target_words = WordList::from_file(Path::new("answers.txt")).unwrap();
let mut game = Game::new(target_words.random_word()); let target_word = target_words.random_word();
println!("Target: {}", target_word);
let mut game = Game::new(target_word);
let mut solver = Solver::new(valid_words, target_words); let mut solver = Solver::new(valid_words, target_words);
+4
View File
@@ -58,6 +58,10 @@ impl Solver {
let information_gained = self.possible_solutions.equal_likelieness_entropy() let information_gained = self.possible_solutions.equal_likelieness_entropy()
- new_possible_solutions.equal_likelieness_entropy(); - new_possible_solutions.equal_likelieness_entropy();
if new_possible_solutions.len() == 0 {
panic!("Solution space is empty");
}
self.possible_solutions = new_possible_solutions; self.possible_solutions = new_possible_solutions;
self.guesses.push(Guess { self.guesses.push(Guess {