From 43464a0cd620942b1ac59cb6a6cf309b68f77c8d Mon Sep 17 00:00:00 2001 From: Rhys Lloyd Date: Fri, 15 May 2026 06:05:11 -0700 Subject: [PATCH] Initial commit --- .gitignore | 1 + Cargo.lock | 16 ++++++++++++++++ Cargo.toml | 7 +++++++ rustfmt.toml | 1 + src/card_game.rs | 39 +++++++++++++++++++++++++++++++++++++++ src/klondike.rs | 34 ++++++++++++++++++++++++++++++++++ src/lib.rs | 2 ++ 7 files changed, 100 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 rustfmt.toml create mode 100644 src/card_game.rs create mode 100644 src/klondike.rs create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..cf83f94 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,16 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "card_game" +version = "0.1.0" +dependencies = [ + "deranged", +] + +[[package]] +name = "deranged" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..faee622 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "card_game" +version = "0.1.0" +edition = "2024" + +[dependencies] +deranged = "0.5.8" diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..7c224aa --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +hard_tabs=true diff --git a/src/card_game.rs b/src/card_game.rs new file mode 100644 index 0000000..6b7c227 --- /dev/null +++ b/src/card_game.rs @@ -0,0 +1,39 @@ +// TODO: pub struct ValidInstruction(I); +pub trait Game { + type Instruction; + fn enumerate_instructions(&self) -> impl Iterator; + fn validate_instruction(&self, instruction: Self::Instruction) -> bool; + fn process_instruction(&mut self, instruction: Self::Instruction); +} + +pub struct Card(u8); +pub struct CardValue(deranged::RangedU8<1, 13>); +pub enum Suit { + Spades, + Hearts, + Clubs, + Diamonds, +} + +pub struct Stack(Vec); + +pub struct Session { + state: G, + history: Vec, +} +impl Game for Session +where + G::Instruction: Clone, +{ + type Instruction = G::Instruction; + fn enumerate_instructions(&self) -> impl Iterator { + self.state.enumerate_instructions() + } + fn validate_instruction(&self, instruction: Self::Instruction) -> bool { + self.state.validate_instruction(instruction) + } + fn process_instruction(&mut self, instruction: Self::Instruction) { + self.history.push(instruction.clone()); + self.state.process_instruction(instruction); + } +} diff --git a/src/klondike.rs b/src/klondike.rs new file mode 100644 index 0000000..5ac8d4f --- /dev/null +++ b/src/klondike.rs @@ -0,0 +1,34 @@ +use crate::card_game::{Card, Game, Stack}; + +struct Pile { + face_down: Stack, + face_up: Stack, +} +struct KlondikeConfig {} +struct KlondikeState { + piles: [Pile; 14], +} +enum KlondikePileId { + Stock, + Hand, + Foundation0, + Foundation1, + Foundation2, + Foundation3, + Tableau0, + Tableau1, + Tableau2, + Tableau3, + Tableau4, + Tableau5, + Tableau6, + Tableau7, +} +struct KlondikeMove { + src: KlondikePileId, + dst: KlondikePileId, +} +pub struct KlondikeGame { + config: KlondikeConfig, + state: KlondikeState, +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..4a623ec --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,2 @@ +mod card_game; +mod klondike;