From b8624ef9d0615de438cc55942ed5ed56a05d0b3f Mon Sep 17 00:00:00 2001 From: Rhys Lloyd Date: Fri, 15 May 2026 15:24:27 -0700 Subject: [PATCH] add auto play --- src/main.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index d48a3f7..a7c543d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -120,6 +120,7 @@ enum SessionInstruction { New, Undo, Hint, + Auto, Stock, Klondike(KlondikeInstruction), } @@ -127,9 +128,10 @@ impl core::str::FromStr for SessionInstruction { type Err = Invalid; fn from_str(s: &str) -> Result { Ok(match s { - "NEW" | "new" => Self::New, - "UNDO" | "undo" => Self::Undo, - "HINT" | "hint" => Self::Hint, + "NEW" | "new" | "n" => Self::New, + "UNDO" | "undo" | "u" => Self::Undo, + "HINT" | "hint" | "h" => Self::Hint, + "AUTO" | "auto" | "a" => Self::Auto, "s" => Self::Stock, other => { let Parsed(ki) = other.parse()?; @@ -162,6 +164,13 @@ fn main() -> Result<(), std::io::Error> { 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::Klondike(instruction) => { if session.is_instruction_valid(instruction) {