stock shorthand
This commit is contained in:
@@ -52,6 +52,12 @@ pub struct KlondikeInstruction {
|
|||||||
pub dst: KlondikePileId,
|
pub dst: KlondikePileId,
|
||||||
}
|
}
|
||||||
impl KlondikeInstruction {
|
impl KlondikeInstruction {
|
||||||
|
pub fn stock() -> Self {
|
||||||
|
Self {
|
||||||
|
src: KlondikePileId::Stock,
|
||||||
|
dst: KlondikePileId::Stock,
|
||||||
|
}
|
||||||
|
}
|
||||||
fn next(self) -> Option<Self> {
|
fn next(self) -> Option<Self> {
|
||||||
let KlondikeInstruction { src, dst } = self;
|
let KlondikeInstruction { src, dst } = self;
|
||||||
if let Some(next_dst) = dst.next() {
|
if let Some(next_dst) = dst.next() {
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ enum SessionInstruction {
|
|||||||
New,
|
New,
|
||||||
Undo,
|
Undo,
|
||||||
Hint,
|
Hint,
|
||||||
|
Stock,
|
||||||
Klondike(KlondikeInstruction),
|
Klondike(KlondikeInstruction),
|
||||||
}
|
}
|
||||||
impl core::str::FromStr for SessionInstruction {
|
impl core::str::FromStr for SessionInstruction {
|
||||||
@@ -131,6 +132,7 @@ impl core::str::FromStr for SessionInstruction {
|
|||||||
"NEW" | "new" => Self::New,
|
"NEW" | "new" => Self::New,
|
||||||
"UNDO" | "undo" => Self::Undo,
|
"UNDO" | "undo" => Self::Undo,
|
||||||
"HINT" | "hint" => Self::Hint,
|
"HINT" | "hint" => Self::Hint,
|
||||||
|
"s" => Self::Stock,
|
||||||
other => {
|
other => {
|
||||||
let Parsed(ki) = other.parse()?;
|
let Parsed(ki) = other.parse()?;
|
||||||
Self::Klondike(ki)
|
Self::Klondike(ki)
|
||||||
@@ -162,6 +164,7 @@ fn main() -> Result<(), std::io::Error> {
|
|||||||
println!("{instruction:?}");
|
println!("{instruction:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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) {
|
||||||
session.process_instruction(instruction);
|
session.process_instruction(instruction);
|
||||||
|
|||||||
Reference in New Issue
Block a user