3 Commits

Author SHA1 Message Date
Quaternions 334084e4df stock shorthand 2026-05-15 12:43:18 -07:00
Quaternions 792c9acba3 add new game command 2026-05-15 12:38:40 -07:00
Quaternions a5ca7ff25d fix human numbers 2026-05-15 12:38:35 -07:00
2 changed files with 13 additions and 1 deletions
+6
View File
@@ -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() {
+7 -1
View File
@@ -70,7 +70,7 @@ impl Display for Klondike {
.into_iter() .into_iter()
.enumerate() .enumerate()
{ {
write!(f, "T{i} ")?; write!(f, "T{} ", i + 1)?;
let pile = self.pile(tableau); let pile = self.pile(tableau);
for _ in pile.face_down() { for _ in pile.face_down() {
write!(f, "]")?; write!(f, "]")?;
@@ -119,16 +119,20 @@ impl core::str::FromStr for Parsed<KlondikePileId> {
} }
enum SessionInstruction { enum SessionInstruction {
New,
Undo, Undo,
Hint, Hint,
Stock,
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" => 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)
@@ -153,12 +157,14 @@ fn main() -> Result<(), std::io::Error> {
// run game // run game
match instruction { match instruction {
SessionInstruction::New => session = Session::new(Klondike::new_random_default()),
SessionInstruction::Undo => session.undo(), SessionInstruction::Undo => session.undo(),
SessionInstruction::Hint => { SessionInstruction::Hint => {
for instruction in session.possible_instructions() { for instruction in session.possible_instructions() {
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);