feat(web): add solver output

This commit is contained in:
2026-08-21 15:49:24 +02:00
parent 8d501d42a3
commit 7667ff24cd
9 changed files with 238 additions and 25 deletions
+40
View File
@@ -21,6 +21,30 @@ pub enum Color {
GREEN,
}
#[wasm_bindgen]
pub struct WordStats(solver::WordStats);
#[allow(dead_code)]
#[wasm_bindgen]
impl WordStats {
#[wasm_bindgen(getter)]
pub fn word(&self) -> String {
self.0.word.clone()
}
#[wasm_bindgen(getter)]
pub fn solution_probability(&self) -> f64 {
self.0.solution_probability
}
#[wasm_bindgen(getter)]
pub fn expected_information_gained(&self) -> f64 {
self.0.expected_information_gained
}
#[wasm_bindgen(getter)]
pub fn expected_score_after_guess(&self) -> f64 {
self.0.expected_score_after_guess
}
}
#[allow(dead_code)]
#[wasm_bindgen]
impl Solver {
@@ -50,6 +74,22 @@ impl Solver {
Ok(())
}
pub fn evaluate_words(
&self,
n: u32,
progress: js_sys::Function,
) -> Result<Vec<WordStats>, String> {
Ok(self
.0
.evaluate_all_words_cb(move |i, n| {
let _ = progress.call2(&JsValue::NULL, &JsValue::from(i), &JsValue::from(n));
})?
.into_iter()
.take(n as usize)
.map(|ws| WordStats(ws))
.collect())
}
pub fn guess_infos(&self) -> Vec<f64> {
self.0
.guesses()