From 27c308d632ac9658bd6c2b83c3c301c8ead6a729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20R=C3=B6ger?= Date: Thu, 20 Aug 2026 19:04:10 +0200 Subject: [PATCH] feat(web): solver input --- src/lib/solver.rs | 17 +++++-- src/lib/wasm.rs | 23 +++++---- web/src/App.svelte | 73 ++++++++++++++++++++-------- web/src/components/WordleLine.svelte | 71 +++++++++++++++++++++++++++ 4 files changed, 151 insertions(+), 33 deletions(-) create mode 100644 web/src/components/WordleLine.svelte diff --git a/src/lib/solver.rs b/src/lib/solver.rs index ad11e0e..0086c44 100644 --- a/src/lib/solver.rs +++ b/src/lib/solver.rs @@ -7,9 +7,9 @@ use crate::word_list::WordList; use derive_more::Display; use tabular::{Row, Table}; -struct Guess { - pattern: Pattern, - information_gained: f64, +pub struct Guess { + pub pattern: Pattern, + pub information_gained: f64, } pub struct Solver { @@ -141,6 +141,17 @@ impl Solver { table.to_string() } + pub fn guesses(&self) -> &Vec { + &self.guesses + } + + pub fn stats(&self) -> (u64, f64) { + ( + self.possible_solutions.len() as u64, + self.possible_solutions.equal_likelieness_entropy(), + ) + } + pub fn tabular_format(&self) -> String { let mut table = Table::new("{:<} | {:<}"); diff --git a/src/lib/wasm.rs b/src/lib/wasm.rs index ce9e14c..bbe268e 100644 --- a/src/lib/wasm.rs +++ b/src/lib/wasm.rs @@ -21,11 +21,6 @@ pub enum Color { GREEN, } -#[wasm_bindgen] -extern "C" { - pub fn alert(msg: &str); -} - #[allow(dead_code)] #[wasm_bindgen] impl Solver { @@ -50,14 +45,24 @@ impl Solver { .collect(), )?; - alert(&format!("{:?}", pat)); - self.0.apply_guess(pat)?; Ok(()) } - pub fn stats(&self) -> String { - self.0.tabular_format() + pub fn guess_infos(&self) -> Vec { + self.0 + .guesses() + .iter() + .map(|g| g.information_gained) + .collect() + } + + pub fn solution_space(&self) -> u64 { + self.0.stats().0 + } + + pub fn solution_space_uncertainty(&self) -> f64 { + self.0.stats().1 } } diff --git a/web/src/App.svelte b/web/src/App.svelte index 34c394f..a907521 100644 --- a/web/src/App.svelte +++ b/web/src/App.svelte @@ -1,33 +1,64 @@ + +

- svelte tests + Wordle Solver

- +

+ Solution-space: {solution_space} · {solution_space_uncertainty.toFixed(2)}bits +

+ +
+ {#each guesses as g,i (g)} + + {/each} +
+ + +

+ Type letters · ← → navigate · Space cycle color · Backspace delete · Enter apply +

diff --git a/web/src/components/WordleLine.svelte b/web/src/components/WordleLine.svelte new file mode 100644 index 0000000..94e275f --- /dev/null +++ b/web/src/components/WordleLine.svelte @@ -0,0 +1,71 @@ + + + + +
+ {#each letters as letter, i} +
+ {letter} +
+ {/each} + { + (info_gained !== null) ? info_gained.toFixed(2) + "bits" : '↵' + } +