generated from PlexSheep/rs-base
This commit is contained in:
parent
3800b9068b
commit
740f2fbdc1
|
@ -54,9 +54,6 @@ struct Cli {
|
|||
|
||||
#[derive(Subcommand, Debug, EnumIter, Clone)]
|
||||
enum ReplCommand {
|
||||
/// Let the user input the response to the last guess
|
||||
///
|
||||
Response { encoded: String },
|
||||
/// Let the user input a word and the response for that word
|
||||
///
|
||||
/// Evaluation Format:
|
||||
|
@ -86,6 +83,10 @@ enum ReplCommand {
|
|||
#[command(subcommand)]
|
||||
cmd: WlCommand,
|
||||
},
|
||||
/// Start a new game
|
||||
New,
|
||||
/// Undo the last n operations
|
||||
Undo { n: usize },
|
||||
/// Leave the Repl
|
||||
Exit,
|
||||
}
|
||||
|
@ -155,9 +156,13 @@ fn help_guess_interactive(cli: Cli) -> anyhow::Result<()> {
|
|||
println!("{}", game);
|
||||
}
|
||||
ReplCommand::Solve => {
|
||||
let best_guess = solver.guess_for(&game)?;
|
||||
let best_guess = solver.guess_for(&game);
|
||||
if best_guess.is_err() {
|
||||
eprintln!("{}", style(best_guess.unwrap_err()).red().bold());
|
||||
continue;
|
||||
}
|
||||
debug!("game state: {game:?}");
|
||||
println!("best guess: {best_guess}");
|
||||
println!("best guess: {}", best_guess.unwrap());
|
||||
}
|
||||
ReplCommand::Guess {
|
||||
your_guess,
|
||||
|
@ -174,7 +179,8 @@ fn help_guess_interactive(cli: Cli) -> anyhow::Result<()> {
|
|||
println!("{}", guess.unwrap());
|
||||
debug!("game state: {game:#?}");
|
||||
}
|
||||
_ => todo!(),
|
||||
ReplCommand::New => game = builder.build()?,
|
||||
ReplCommand::Undo { n } => game.undo(n)?,
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -133,6 +133,13 @@ impl<'wl, WL: WordList> Game<'wl, WL> {
|
|||
evaluation.into()
|
||||
}
|
||||
|
||||
/// discard the last n responses
|
||||
pub fn undo(&mut self, n: usize) -> WResult<()> {
|
||||
self.responses
|
||||
.drain(self.responses.len() - n..self.responses.len());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn length(&self) -> usize {
|
||||
self.length
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue