From 344d188f07c992270966748c50e811ed80de9f35 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Fri, 22 Mar 2024 15:02:59 +0100 Subject: [PATCH] stupid solver --- src/bin/solve/simple.rs | 2 +- src/solve/mod.rs | 10 ++++++++-- src/solve/stupid/mod.rs | 8 +++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/bin/solve/simple.rs b/src/bin/solve/simple.rs index 2b3d28f..ebe58c4 100644 --- a/src/bin/solve/simple.rs +++ b/src/bin/solve/simple.rs @@ -58,7 +58,7 @@ fn main() -> anyhow::Result<()> { let mut _guess: Word; loop { response = solver.play(&mut game)?; - println!("{response}"); + println!("{}. guess: {response}", game.step() - 1); if response.finished() { break; diff --git a/src/solve/mod.rs b/src/solve/mod.rs index eb4f1c2..cdbe15b 100644 --- a/src/solve/mod.rs +++ b/src/solve/mod.rs @@ -3,7 +3,10 @@ use std::{fmt::Display, str::FromStr}; use crate::{ error::{Error, WResult}, game::{response::*, summary::Summary, Game}, - wlist::{word::WordData, WordList}, + wlist::{ + word::{Word, WordData}, + WordList, + }, }; pub mod naive; @@ -11,7 +14,10 @@ pub mod stupid; pub trait Solver<'wl, WL: WordList>: Clone + std::fmt::Debug { fn build(wordlist: &'wl WL) -> WResult; - fn play(&self, game: &mut Game<'wl, WL>) -> WResult; + fn guess_for(&self, game: &Game<'wl, WL>) -> Word; + fn play(&self, game: &mut Game<'wl, WL>) -> WResult { + Ok(game.guess(self.guess_for(&game))?) + } fn solve(&self, game: &mut Game<'wl, WL>) -> WResult> { let mut resp: GuessResponse; loop { diff --git a/src/solve/stupid/mod.rs b/src/solve/stupid/mod.rs index 17f6c33..5e69298 100644 --- a/src/solve/stupid/mod.rs +++ b/src/solve/stupid/mod.rs @@ -1,3 +1,4 @@ +use crate::wlist::word::Word; use crate::wlist::WordList; use super::Solver; @@ -11,10 +12,7 @@ impl<'wl, WL: WordList> Solver<'wl, WL> for StupidSolver<'wl, WL> { fn build(wordlist: &'wl WL) -> crate::error::WResult { Ok(Self { wl: wordlist }) } - fn play( - &self, - game: &mut crate::game::Game<'wl, WL>, - ) -> crate::error::WResult { - todo!() + fn guess_for(&self, game: &crate::game::Game<'wl, WL>) -> Word { + Word::from("hello") } }