add auto play

This commit is contained in:
2026-05-15 15:24:27 -07:00
parent 10444b0a62
commit b8624ef9d0
+12 -3
View File
@@ -120,6 +120,7 @@ enum SessionInstruction {
New, New,
Undo, Undo,
Hint, Hint,
Auto,
Stock, Stock,
Klondike(KlondikeInstruction), Klondike(KlondikeInstruction),
} }
@@ -127,9 +128,10 @@ impl core::str::FromStr for SessionInstruction {
type Err = Invalid; type Err = Invalid;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s { Ok(match s {
"NEW" | "new" => Self::New, "NEW" | "new" | "n" => Self::New,
"UNDO" | "undo" => Self::Undo, "UNDO" | "undo" | "u" => Self::Undo,
"HINT" | "hint" => Self::Hint, "HINT" | "hint" | "h" => Self::Hint,
"AUTO" | "auto" | "a" => Self::Auto,
"s" => Self::Stock, "s" => Self::Stock,
other => { other => {
let Parsed(ki) = other.parse()?; let Parsed(ki) = other.parse()?;
@@ -162,6 +164,13 @@ fn main() -> Result<(), std::io::Error> {
println!("{instruction:?}"); println!("{instruction:?}");
} }
} }
SessionInstruction::Auto => {
if let Some(instruction) = session.possible_instructions().next() {
session.process_instruction(instruction);
} else {
println!("No valid moves!");
}
}
SessionInstruction::Stock => session.process_instruction(KlondikeInstruction::stock()), SessionInstruction::Stock => session.process_instruction(KlondikeInstruction::stock()),
SessionInstruction::Klondike(instruction) => { SessionInstruction::Klondike(instruction) => {
if session.is_instruction_valid(instruction) { if session.is_instruction_valid(instruction) {