card game stuff

This commit is contained in:
2026-05-15 06:53:18 -07:00
parent 09edadc822
commit 77b38608d9
5 changed files with 428 additions and 4 deletions
+16
View File
@@ -1,3 +1,5 @@
use crate::Rng;
// TODO: pub struct ValidInstruction<I>(I);
pub trait Game {
type Instruction;
@@ -61,12 +63,26 @@ impl Stack {
}
Stack(stack)
}
pub fn shuffle<R: rand::Rng>(&mut self, rng: &mut R) {
use rand::seq::SliceRandom;
self.0.shuffle(rng);
}
}
pub struct Session<G: Game> {
seed: Rng,
state: G,
history: Vec<G::Instruction>,
}
impl<G: Game> Session<G> {
pub fn new(seed: Rng, state: G) -> Self {
Self {
seed,
state,
history: Vec::new(),
}
}
}
impl<G: Game> Game for Session<G>
where
G::Instruction: Clone,
+17 -3
View File
@@ -1,3 +1,4 @@
use crate::Rng;
use crate::card_game::{Card, Game, Stack};
struct Pile {
@@ -24,7 +25,7 @@ enum KlondikePileId {
Tableau6,
Tableau7,
}
struct KlondikeMove {
pub struct KlondikeInstruction {
src: KlondikePileId,
dst: KlondikePileId,
}
@@ -33,8 +34,21 @@ pub struct Klondike {
state: KlondikeState,
}
impl Klondike {
pub fn new() -> Self {
let deck = Stack::full_deck(0);
pub fn new(mut seed: Rng) -> Self {
let mut deck = Stack::full_deck(0);
deck.shuffle(&mut seed);
unimplemented!()
}
}
impl Game for Klondike {
type Instruction = KlondikeInstruction;
fn enumerate_instructions(&self) -> impl Iterator<Item = Self::Instruction> {
vec![].into_iter()
}
fn validate_instruction(&self, instruction: Self::Instruction) -> bool {
todo!()
}
fn process_instruction(&mut self, instruction: Self::Instruction) {
todo!()
}
}
+2
View File
@@ -1,6 +1,8 @@
pub mod card_game;
pub mod klondike;
pub type Rng = rand::rngs::ThreadRng;
// test readme
#[doc = include_str!("../README.md")]
#[cfg(doctest)]