2 Commits

Author SHA1 Message Date
Quaternions 1cf1db4512 remove upper case matching 2026-05-16 10:09:29 -07:00
Quaternions 2a53f29a9b add exit command 2026-05-16 10:09:15 -07:00
+31 -28
View File
@@ -101,18 +101,18 @@ impl core::str::FromStr for Parsed<InstructionSrc> {
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(Parsed(match s { Ok(Parsed(match s {
"ST" | "st" => InstructionSrc::new(KlondikePileStack::Stock), "st" => InstructionSrc::new(KlondikePileStack::Stock),
"T1" | "t1" => InstructionSrc::new(KlondikePileStack::Tableau1(SkipCards::Zero)), "t1" => InstructionSrc::new(KlondikePileStack::Tableau1(SkipCards::Zero)),
"T2" | "t2" => InstructionSrc::new(KlondikePileStack::Tableau2(SkipCards::Zero)), "t2" => InstructionSrc::new(KlondikePileStack::Tableau2(SkipCards::Zero)),
"T3" | "t3" => InstructionSrc::new(KlondikePileStack::Tableau3(SkipCards::Zero)), "t3" => InstructionSrc::new(KlondikePileStack::Tableau3(SkipCards::Zero)),
"T4" | "t4" => InstructionSrc::new(KlondikePileStack::Tableau4(SkipCards::Zero)), "t4" => InstructionSrc::new(KlondikePileStack::Tableau4(SkipCards::Zero)),
"T5" | "t5" => InstructionSrc::new(KlondikePileStack::Tableau5(SkipCards::Zero)), "t5" => InstructionSrc::new(KlondikePileStack::Tableau5(SkipCards::Zero)),
"T6" | "t6" => InstructionSrc::new(KlondikePileStack::Tableau6(SkipCards::Zero)), "t6" => InstructionSrc::new(KlondikePileStack::Tableau6(SkipCards::Zero)),
"T7" | "t7" => InstructionSrc::new(KlondikePileStack::Tableau7(SkipCards::Zero)), "t7" => InstructionSrc::new(KlondikePileStack::Tableau7(SkipCards::Zero)),
"F1" | "f1" => InstructionSrc::new(KlondikePileStack::Foundation1), "f1" => InstructionSrc::new(KlondikePileStack::Foundation1),
"F2" | "f2" => InstructionSrc::new(KlondikePileStack::Foundation2), "f2" => InstructionSrc::new(KlondikePileStack::Foundation2),
"F3" | "f3" => InstructionSrc::new(KlondikePileStack::Foundation3), "f3" => InstructionSrc::new(KlondikePileStack::Foundation3),
"F4" | "f4" => InstructionSrc::new(KlondikePileStack::Foundation4), "f4" => InstructionSrc::new(KlondikePileStack::Foundation4),
_ => return Err(Invalid), _ => return Err(Invalid),
})) }))
} }
@@ -121,18 +121,18 @@ impl core::str::FromStr for Parsed<KlondikePileId> {
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(Parsed(match s { Ok(Parsed(match s {
"ST" | "st" => KlondikePileId::Stock, "st" => KlondikePileId::Stock,
"T1" | "t1" => KlondikePileId::Tableau1, "t1" => KlondikePileId::Tableau1,
"T2" | "t2" => KlondikePileId::Tableau2, "t2" => KlondikePileId::Tableau2,
"T3" | "t3" => KlondikePileId::Tableau3, "t3" => KlondikePileId::Tableau3,
"T4" | "t4" => KlondikePileId::Tableau4, "t4" => KlondikePileId::Tableau4,
"T5" | "t5" => KlondikePileId::Tableau5, "t5" => KlondikePileId::Tableau5,
"T6" | "t6" => KlondikePileId::Tableau6, "t6" => KlondikePileId::Tableau6,
"T7" | "t7" => KlondikePileId::Tableau7, "t7" => KlondikePileId::Tableau7,
"F1" | "f1" => KlondikePileId::Foundation1, "f1" => KlondikePileId::Foundation1,
"F2" | "f2" => KlondikePileId::Foundation2, "f2" => KlondikePileId::Foundation2,
"F3" | "f3" => KlondikePileId::Foundation3, "f3" => KlondikePileId::Foundation3,
"F4" | "f4" => KlondikePileId::Foundation4, "f4" => KlondikePileId::Foundation4,
_ => return Err(Invalid), _ => return Err(Invalid),
})) }))
} }
@@ -144,16 +144,18 @@ enum SessionInstruction {
Hint, Hint,
Auto, Auto,
Stock, Stock,
Exit,
Klondike(KlondikeInstruction), Klondike(KlondikeInstruction),
} }
impl core::str::FromStr for SessionInstruction { 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" | "n" => Self::New, "new" | "n" => Self::New,
"UNDO" | "undo" | "u" => Self::Undo, "undo" | "u" => Self::Undo,
"HINT" | "hint" | "h" => Self::Hint, "hint" | "h" => Self::Hint,
"AUTO" | "auto" | "a" => Self::Auto, "auto" | "a" => Self::Auto,
"exit" => Self::Exit,
"s" => Self::Stock, "s" => Self::Stock,
other => { other => {
let Parsed(ki) = other.parse()?; let Parsed(ki) = other.parse()?;
@@ -181,6 +183,7 @@ fn main() -> Result<(), std::io::Error> {
match instruction { match instruction {
SessionInstruction::New => session = Session::new(Klondike::new_random_default()), SessionInstruction::New => session = Session::new(Klondike::new_random_default()),
SessionInstruction::Undo => session.undo(), SessionInstruction::Undo => session.undo(),
SessionInstruction::Exit => break Ok(()),
SessionInstruction::Hint => { SessionInstruction::Hint => {
for instruction in session.possible_instructions() { for instruction in session.possible_instructions() {
println!("{instruction:?}"); println!("{instruction:?}");