From 416ab6beba2adff4deacd955a2b59c622191ee83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20R=C3=B6ger?= Date: Tue, 18 Aug 2026 20:33:26 +0200 Subject: [PATCH] add panic if solution space is empty --- src/app/wordle_simulation.rs | 4 +++- src/lib/solver.rs | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/app/wordle_simulation.rs b/src/app/wordle_simulation.rs index 272a1a2..0dfcab0 100644 --- a/src/app/wordle_simulation.rs +++ b/src/app/wordle_simulation.rs @@ -5,7 +5,9 @@ use wordle_solver::{game::Game, solver::Solver, word_list::WordList}; pub fn main() { let valid_words = WordList::from_file(Path::new("valid-words.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); diff --git a/src/lib/solver.rs b/src/lib/solver.rs index 5e16395..3c372b0 100644 --- a/src/lib/solver.rs +++ b/src/lib/solver.rs @@ -58,6 +58,10 @@ impl Solver { let information_gained = self.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.guesses.push(Guess {