Initial commit

This commit is contained in:
2026-05-15 06:05:11 -07:00
commit 43464a0cd6
7 changed files with 100 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
/target
Generated
+16
View File
@@ -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"
+7
View File
@@ -0,0 +1,7 @@
[package]
name = "card_game"
version = "0.1.0"
edition = "2024"
[dependencies]
deranged = "0.5.8"
+1
View File
@@ -0,0 +1 @@
hard_tabs=true
+39
View File
@@ -0,0 +1,39 @@
// TODO: pub struct ValidInstruction<I>(I);
pub trait Game {
type Instruction;
fn enumerate_instructions(&self) -> impl Iterator<Item = Self::Instruction>;
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<Card>);
pub struct Session<G: Game> {
state: G,
history: Vec<G::Instruction>,
}
impl<G: Game> Game for Session<G>
where
G::Instruction: Clone,
{
type Instruction = G::Instruction;
fn enumerate_instructions(&self) -> impl Iterator<Item = Self::Instruction> {
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);
}
}
+34
View File
@@ -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,
}
+2
View File
@@ -0,0 +1,2 @@
mod card_game;
mod klondike;