generated from PlexSheep/rs-base
improve naive solver #13
|
@ -0,0 +1,57 @@
|
|||
use wordle_analyzer::error::GameError;
|
||||
use wordle_analyzer::game::evaluation::Evaluation;
|
||||
use wordle_analyzer::game::response::GuessResponse;
|
||||
use wordle_analyzer::wlist::builtin::BuiltinWList;
|
||||
use wordle_analyzer::wlist::WordList;
|
||||
|
||||
use wordle_analyzer::wlist::word::Word;
|
||||
use wordle_analyzer::{self, game};
|
||||
|
||||
fn wordlist() -> impl WordList {
|
||||
BuiltinWList::default()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_eval_simple() -> anyhow::Result<()> {
|
||||
let wl = wordlist();
|
||||
let builder = game::Game::builder(&wl)
|
||||
.length(5)
|
||||
.max_steps(6)
|
||||
.solution(Some(wl.get_word(&Word::from("crate")).unwrap()))
|
||||
.precompute(false);
|
||||
|
||||
let mut game = builder.build()?;
|
||||
let guess = Word::from("slate");
|
||||
game.guess(&guess, None)?;
|
||||
assert_eq!(
|
||||
*game.last_response().unwrap().evaluation(),
|
||||
Evaluation::build(&guess, "xxccc")?
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_eval_reoccuring_char() -> anyhow::Result<()> {
|
||||
let wl = wordlist();
|
||||
let builder = game::Game::builder(&wl)
|
||||
.solution(Some(wl.get_word(&Word::from("nines")).unwrap()))
|
||||
.precompute(false);
|
||||
|
||||
let mut game = builder.build()?;
|
||||
let guess = Word::from("pines");
|
||||
game.guess(&guess, None)?;
|
||||
assert_eq!(
|
||||
*game.last_response().unwrap().evaluation(),
|
||||
Evaluation::build(&guess, "xcccc")?
|
||||
);
|
||||
|
||||
let mut game = builder.build()?;
|
||||
let guess = Word::from("sides");
|
||||
game.guess(&guess, None)?;
|
||||
assert_eq!(
|
||||
*game.last_response().unwrap().evaluation(),
|
||||
Evaluation::build(&guess, "xcxcc")?
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -36,22 +36,17 @@ fn test_naive_play_predetermined_game() -> anyhow::Result<()> {
|
|||
sl.make_a_move(&mut game)?;
|
||||
assert_eq!(
|
||||
game.responses().last().unwrap().guess(),
|
||||
&Word::from("their")
|
||||
&Word::from("first")
|
||||
);
|
||||
sl.make_a_move(&mut game)?;
|
||||
assert_eq!(
|
||||
game.responses().last().unwrap().guess(),
|
||||
&Word::from("being")
|
||||
&Word::from("lives")
|
||||
);
|
||||
sl.make_a_move(&mut game)?;
|
||||
assert_eq!(
|
||||
game.responses().last().unwrap().guess(),
|
||||
&Word::from("since")
|
||||
);
|
||||
sl.make_a_move(&mut game)?;
|
||||
assert_eq!(
|
||||
game.responses().last().unwrap().guess(),
|
||||
&Word::from("lines")
|
||||
&Word::from("sides")
|
||||
);
|
||||
sl.make_a_move(&mut game)?;
|
||||
assert_eq!(
|
||||
|
@ -61,12 +56,16 @@ fn test_naive_play_predetermined_game() -> anyhow::Result<()> {
|
|||
sl.make_a_move(&mut game)?;
|
||||
assert_eq!(
|
||||
game.responses().last().unwrap().guess(),
|
||||
&Word::from("wines")
|
||||
&Word::from("pines")
|
||||
);
|
||||
sl.make_a_move(&mut game)?;
|
||||
assert_eq!(
|
||||
game.responses().last().unwrap().guess(),
|
||||
&Word::from("nines")
|
||||
);
|
||||
|
||||
// naive is at the moment too bad to solve "nines"
|
||||
assert!(game.finished());
|
||||
assert!(!game.won());
|
||||
assert!(game.won());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -85,55 +84,54 @@ fn test_naive_play_predetermined_game_manually() -> anyhow::Result<()> {
|
|||
next_guess = sl.guess_for(&game)?;
|
||||
assert_eq!(next_guess, Word::from("which"));
|
||||
game.guess(
|
||||
next_guess.clone(),
|
||||
&next_guess.clone(),
|
||||
Some(Evaluation::build(&next_guess, "xxfxx")?),
|
||||
)?;
|
||||
|
||||
next_guess = sl.guess_for(&game)?;
|
||||
assert_eq!(next_guess, Word::from("their"));
|
||||
assert_eq!(next_guess, Word::from("first"));
|
||||
game.guess(
|
||||
next_guess.clone(),
|
||||
Some(Evaluation::build(&next_guess, "xxffx")?),
|
||||
&next_guess.clone(),
|
||||
Some(Evaluation::build(&next_guess, "xcxfx")?),
|
||||
)?;
|
||||
|
||||
next_guess = sl.guess_for(&game)?;
|
||||
assert_eq!(next_guess, Word::from("being"));
|
||||
assert_eq!(next_guess, Word::from("lives"));
|
||||
game.guess(
|
||||
next_guess.clone(),
|
||||
Some(Evaluation::build(&next_guess, "xfffx")?),
|
||||
&next_guess.clone(),
|
||||
Some(Evaluation::build(&next_guess, "xcxcc")?),
|
||||
)?;
|
||||
|
||||
next_guess = sl.guess_for(&game)?;
|
||||
assert_eq!(next_guess, Word::from("since"));
|
||||
assert_eq!(next_guess, Word::from("sides"));
|
||||
game.guess(
|
||||
next_guess.clone(),
|
||||
Some(Evaluation::build(&next_guess, "fcfxf")?),
|
||||
)?;
|
||||
|
||||
next_guess = sl.guess_for(&game)?;
|
||||
assert_eq!(next_guess, Word::from("lines"));
|
||||
game.guess(
|
||||
next_guess.clone(),
|
||||
Some(Evaluation::build(&next_guess, "xcccc")?),
|
||||
&next_guess.clone(),
|
||||
Some(Evaluation::build(&next_guess, "xcxcc")?),
|
||||
)?;
|
||||
|
||||
next_guess = sl.guess_for(&game)?;
|
||||
assert_eq!(next_guess, Word::from("mines"));
|
||||
game.guess(
|
||||
next_guess.clone(),
|
||||
&next_guess.clone(),
|
||||
Some(Evaluation::build(&next_guess, "xcccc")?),
|
||||
)?;
|
||||
|
||||
next_guess = sl.guess_for(&game)?;
|
||||
assert_eq!(next_guess, Word::from("wines"));
|
||||
assert_eq!(next_guess, Word::from("pines"));
|
||||
game.guess(
|
||||
next_guess.clone(),
|
||||
&next_guess.clone(),
|
||||
Some(Evaluation::build(&next_guess, "xcccc")?),
|
||||
)?;
|
||||
|
||||
// naive is at the moment too bad to solve "nines"
|
||||
next_guess = sl.guess_for(&game)?;
|
||||
assert_eq!(next_guess, Word::from("nines"));
|
||||
game.guess(
|
||||
&next_guess.clone(),
|
||||
Some(Evaluation::build(&next_guess, "ccccc")?),
|
||||
)?;
|
||||
|
||||
assert!(game.finished());
|
||||
assert!(!game.won());
|
||||
assert!(game.won());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue