feat(web): solver input

This commit is contained in:
2026-08-20 19:04:10 +02:00
parent ae2cf56081
commit 27c308d632
4 changed files with 151 additions and 33 deletions
+14 -3
View File
@@ -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<Guess> {
&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("{:<} | {:<}");
+14 -9
View File
@@ -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<f64> {
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
}
}