stupid solver

This commit is contained in:
Christoph J. Scherr 2024-03-22 15:02:59 +01:00
parent aba6c723da
commit 344d188f07
Signed by: cscherrNT
GPG Key ID: 8E2B45BC51A27EA7
3 changed files with 12 additions and 8 deletions

View File

@ -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;

View File

@ -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<Self>;
fn play(&self, game: &mut Game<'wl, WL>) -> WResult<GuessResponse>;
fn guess_for(&self, game: &Game<'wl, WL>) -> Word;
fn play(&self, game: &mut Game<'wl, WL>) -> WResult<GuessResponse> {
Ok(game.guess(self.guess_for(&game))?)
}
fn solve(&self, game: &mut Game<'wl, WL>) -> WResult<Option<WordData>> {
let mut resp: GuessResponse;
loop {

View File

@ -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<Self> {
Ok(Self { wl: wordlist })
}
fn play(
&self,
game: &mut crate::game::Game<'wl, WL>,
) -> crate::error::WResult<super::GuessResponse> {
todo!()
fn guess_for(&self, game: &crate::game::Game<'wl, WL>) -> Word {
Word::from("hello")
}
}