generated from PlexSheep/rs-base
refactor(game): guess only needs a &Word
This commit is contained in:
parent
b6f639da67
commit
567d02d48b
|
@ -61,7 +61,7 @@ fn main() -> anyhow::Result<()> {
|
|||
let mut guess: Word;
|
||||
loop {
|
||||
guess = get_word(&cli, game.step())?;
|
||||
response = match game.guess(guess, None) {
|
||||
response = match game.guess(&guess, None) {
|
||||
Ok(r) => r,
|
||||
Err(err) => match err {
|
||||
GameError::GuessHasWrongLength(len) => {
|
||||
|
|
|
@ -181,7 +181,7 @@ fn help_guess_interactive(cli: Cli) -> anyhow::Result<()> {
|
|||
} => {
|
||||
let evaluation_converted: Evaluation =
|
||||
Evaluation::build(&your_guess, &evalutation)?;
|
||||
let guess = game.guess(your_guess, Some(evaluation_converted));
|
||||
let guess = game.guess(&your_guess, Some(evaluation_converted));
|
||||
debug!("your guess: {guess:?}");
|
||||
if guess.is_err() {
|
||||
eprintln!("{}", style(guess.unwrap_err()).red().bold());
|
||||
|
|
|
@ -101,7 +101,7 @@ impl<'wl, WL: WordList> Game<'wl, WL> {
|
|||
///
|
||||
/// This function will return an error if the length of the [Word] is wrong It will also error
|
||||
/// if the game is finished.
|
||||
pub fn guess(&mut self, guess: Word, eval: Option<Evaluation>) -> GameResult<GuessResponse> {
|
||||
pub fn guess(&mut self, guess: &Word, eval: Option<Evaluation>) -> GameResult<GuessResponse> {
|
||||
if guess.len() != self.length {
|
||||
return Err(GameError::GuessHasWrongLength(guess.len()));
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ impl<'wl, WL: WordList> Game<'wl, WL> {
|
|||
return Err(GameError::TryingToPlayAFinishedGame);
|
||||
}
|
||||
if self.wordlist.get_word(&guess).is_none() {
|
||||
return Err(GameError::WordNotInWordlist(guess));
|
||||
return Err(GameError::WordNotInWordlist(guess.to_string()));
|
||||
}
|
||||
self.step += 1;
|
||||
|
||||
|
@ -324,6 +324,14 @@ impl<'wl, WL: WordList> GameBuilder<'wl, WL> {
|
|||
self
|
||||
}
|
||||
|
||||
/// Enable or disable Generation of a solution for this builder
|
||||
///
|
||||
/// Default is true
|
||||
pub fn generate_solution(mut self, generate: bool) -> Self {
|
||||
self.generate_solution = generate;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the solution for the games built by the builder
|
||||
///
|
||||
/// If this is [Some], then the solution generated by
|
||||
|
|
|
@ -51,7 +51,7 @@ pub trait Solver<'wl, WL: WordList>: Clone + std::fmt::Debug + Sized + Sync {
|
|||
///
|
||||
/// This function will return an error if [guess_for](Solver::guess_for) fails.
|
||||
fn make_a_move(&self, game: &mut Game<'wl, WL>) -> WResult<GuessResponse> {
|
||||
Ok(game.guess(self.guess_for(game)?, None)?)
|
||||
Ok(game.guess(&self.guess_for(game)?, None)?)
|
||||
}
|
||||
/// Play a [Game] and return the last [GuessResponse].
|
||||
///
|
||||
|
|
Loading…
Reference in New Issue