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,
}
impl KlondikeInstruction {
pub fn stock() -> Self {
Self {
src: KlondikePileId::Stock,
dst: KlondikePileId::Stock,
}
}
fn next(self) -> Option<Self> {
let KlondikeInstruction { src, dst } = self;
if let Some(next_dst) = dst.next() {
+7 -1
View File
@@ -70,7 +70,7 @@ impl Display for Klondike {
.into_iter()
.enumerate()
{
write!(f, "T{i} ")?;
write!(f, "T{} ", i + 1)?;
let pile = self.pile(tableau);
for _ in pile.face_down() {
write!(f, "]")?;
@@ -119,16 +119,20 @@ impl core::str::FromStr for Parsed<KlondikePileId> {
}
enum SessionInstruction {
New,
Undo,
Hint,
Stock,
Klondike(KlondikeInstruction),
}
impl core::str::FromStr for SessionInstruction {
type Err = Invalid;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"NEW" | "new" => Self::New,
"UNDO" | "undo" => Self::Undo,
"HINT" | "hint" => Self::Hint,
"s" => Self::Stock,
other => {
let Parsed(ki) = other.parse()?;
Self::Klondike(ki)
@@ -153,12 +157,14 @@ fn main() -> Result<(), std::io::Error> {
// run game
match instruction {
SessionInstruction::New => session = Session::new(Klondike::new_random_default()),
SessionInstruction::Undo => session.undo(),
SessionInstruction::Hint => {
for instruction in session.possible_instructions() {
println!("{instruction:?}");
}
}
SessionInstruction::Stock => session.process_instruction(KlondikeInstruction::stock()),
SessionInstruction::Klondike(instruction) => {
if session.is_instruction_valid(instruction) {
session.process_instruction(instruction);