generated from PlexSheep/rs-base
fix: regression fixes and clippy findings
cargo devel CI / cargo CI (push) Failing after 1m41s
Details
cargo devel CI / cargo CI (push) Failing after 1m41s
Details
This commit is contained in:
parent
c140264a0c
commit
32034c9c07
|
@ -108,16 +108,16 @@ impl<'wl, WL: WordList> Game<'wl, WL> {
|
||||||
if self.finished() || self.step > self.max_steps {
|
if self.finished() || self.step > self.max_steps {
|
||||||
return Err(GameError::TryingToPlayAFinishedGame);
|
return Err(GameError::TryingToPlayAFinishedGame);
|
||||||
}
|
}
|
||||||
if self.wordlist.get_word(&guess).is_none() {
|
if self.wordlist.get_word(guess).is_none() {
|
||||||
return Err(GameError::WordNotInWordlist(guess.to_string()));
|
return Err(GameError::WordNotInWordlist(guess.to_string()));
|
||||||
}
|
}
|
||||||
self.step += 1;
|
self.step += 1;
|
||||||
|
|
||||||
let response;
|
let response;
|
||||||
if eval.is_some() && self.solution.is_none() {
|
if eval.is_some() && self.solution.is_none() {
|
||||||
response = GuessResponse::new(&guess, eval.unwrap(), self);
|
response = GuessResponse::new(guess, eval.unwrap(), self);
|
||||||
} else if let Some(solution) = self.solution.clone() {
|
} else if let Some(solution) = self.solution.clone() {
|
||||||
response = GuessResponse::new(&guess, Self::evaluate(solution, &guess), self);
|
response = GuessResponse::new(guess, Self::evaluate(solution, guess), self);
|
||||||
} else {
|
} else {
|
||||||
panic!("there is neither an evaluation nor a predefined solution for this guess");
|
panic!("there is neither an evaluation nor a predefined solution for this guess");
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ impl<'wl, WL: WordList> Game<'wl, WL> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates an [Evaluation] for a given solution and guess.
|
/// Generates an [Evaluation] for a given solution and guess.
|
||||||
pub(crate) fn evaluate(mut solution: WordData, guess: &Word) -> Evaluation {
|
pub(crate) fn evaluate(solution: WordData, guess: &Word) -> Evaluation {
|
||||||
let mut evaluation = Vec::new();
|
let mut evaluation = Vec::new();
|
||||||
let mut status: Status;
|
let mut status: Status;
|
||||||
let mut buf = solution.0.clone();
|
let mut buf = solution.0.clone();
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::collections::HashMap;
|
||||||
use libpt::log::{debug, error, info, trace};
|
use libpt::log::{debug, error, info, trace};
|
||||||
|
|
||||||
use crate::error::{SolverError, WResult};
|
use crate::error::{SolverError, WResult};
|
||||||
use crate::game::evaluation::{Evaluation, EvaluationUnit};
|
use crate::game::evaluation::{Evaluation};
|
||||||
use crate::wlist::word::{Word, WordData};
|
use crate::wlist::word::{Word, WordData};
|
||||||
use crate::wlist::WordList;
|
use crate::wlist::WordList;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ use std::collections::{HashMap, HashSet};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::ops::{Range, RangeBounds};
|
use std::ops::{Range, RangeBounds};
|
||||||
|
|
||||||
use crate::error::WResult;
|
|
||||||
use crate::wlist::word::Word;
|
use crate::wlist::word::Word;
|
||||||
|
|
||||||
pub(crate) type CharMap = HashMap<char, CharInfo>;
|
pub(crate) type CharMap = HashMap<char, CharInfo>;
|
||||||
|
|
|
@ -94,7 +94,7 @@ pub trait WordList: Clone + std::fmt::Debug + Default + Sync + Display {
|
||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
fn get_words_matching(&self, pattern: &str) -> WResult<Vec<WordData>> {
|
fn get_words_matching(&self, pattern: &str) -> WResult<Vec<WordData>> {
|
||||||
let pattern = Regex::new(&pattern).map_err(WordlistError::from)?;
|
let pattern = Regex::new(pattern).map_err(WordlistError::from)?;
|
||||||
let hay = self.raw_wordlist();
|
let hay = self.raw_wordlist();
|
||||||
let keys = pattern.captures_iter(&hay);
|
let keys = pattern.captures_iter(&hay);
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
|
|
@ -85,49 +85,49 @@ fn test_naive_play_predetermined_game_manually() -> anyhow::Result<()> {
|
||||||
next_guess = sl.guess_for(&game)?;
|
next_guess = sl.guess_for(&game)?;
|
||||||
assert_eq!(next_guess, Word::from("which"));
|
assert_eq!(next_guess, Word::from("which"));
|
||||||
game.guess(
|
game.guess(
|
||||||
next_guess.clone(),
|
&next_guess.clone(),
|
||||||
Some(Evaluation::build(&next_guess, "xxfxx")?),
|
Some(Evaluation::build(&next_guess, "xxfxx")?),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
next_guess = sl.guess_for(&game)?;
|
next_guess = sl.guess_for(&game)?;
|
||||||
assert_eq!(next_guess, Word::from("their"));
|
assert_eq!(next_guess, Word::from("their"));
|
||||||
game.guess(
|
game.guess(
|
||||||
next_guess.clone(),
|
&next_guess.clone(),
|
||||||
Some(Evaluation::build(&next_guess, "xxffx")?),
|
Some(Evaluation::build(&next_guess, "xxffx")?),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
next_guess = sl.guess_for(&game)?;
|
next_guess = sl.guess_for(&game)?;
|
||||||
assert_eq!(next_guess, Word::from("being"));
|
assert_eq!(next_guess, Word::from("being"));
|
||||||
game.guess(
|
game.guess(
|
||||||
next_guess.clone(),
|
&next_guess.clone(),
|
||||||
Some(Evaluation::build(&next_guess, "xfffx")?),
|
Some(Evaluation::build(&next_guess, "xfffx")?),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
next_guess = sl.guess_for(&game)?;
|
next_guess = sl.guess_for(&game)?;
|
||||||
assert_eq!(next_guess, Word::from("since"));
|
assert_eq!(next_guess, Word::from("since"));
|
||||||
game.guess(
|
game.guess(
|
||||||
next_guess.clone(),
|
&next_guess.clone(),
|
||||||
Some(Evaluation::build(&next_guess, "fcfxf")?),
|
Some(Evaluation::build(&next_guess, "fcfxf")?),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
next_guess = sl.guess_for(&game)?;
|
next_guess = sl.guess_for(&game)?;
|
||||||
assert_eq!(next_guess, Word::from("lines"));
|
assert_eq!(next_guess, Word::from("lines"));
|
||||||
game.guess(
|
game.guess(
|
||||||
next_guess.clone(),
|
&next_guess.clone(),
|
||||||
Some(Evaluation::build(&next_guess, "xcccc")?),
|
Some(Evaluation::build(&next_guess, "xcccc")?),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
next_guess = sl.guess_for(&game)?;
|
next_guess = sl.guess_for(&game)?;
|
||||||
assert_eq!(next_guess, Word::from("mines"));
|
assert_eq!(next_guess, Word::from("mines"));
|
||||||
game.guess(
|
game.guess(
|
||||||
next_guess.clone(),
|
&next_guess.clone(),
|
||||||
Some(Evaluation::build(&next_guess, "xcccc")?),
|
Some(Evaluation::build(&next_guess, "xcccc")?),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
next_guess = sl.guess_for(&game)?;
|
next_guess = sl.guess_for(&game)?;
|
||||||
assert_eq!(next_guess, Word::from("wines"));
|
assert_eq!(next_guess, Word::from("wines"));
|
||||||
game.guess(
|
game.guess(
|
||||||
next_guess.clone(),
|
&next_guess.clone(),
|
||||||
Some(Evaluation::build(&next_guess, "xcccc")?),
|
Some(Evaluation::build(&next_guess, "xcccc")?),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue