card game stuff
This commit is contained in:
+45
-10
@@ -1,17 +1,16 @@
|
||||
use crate::Rng;
|
||||
use crate::card_game::{Card, Game, Pile, Stack};
|
||||
|
||||
struct KlondikeConfig {}
|
||||
pub struct KlondikeConfig {}
|
||||
impl Default for KlondikeConfig {
|
||||
fn default() -> Self {
|
||||
KlondikeConfig {}
|
||||
}
|
||||
}
|
||||
struct KlondikeState {
|
||||
piles: [Pile; 14],
|
||||
piles: [Pile; 13],
|
||||
}
|
||||
pub enum KlondikePileId {
|
||||
Stock,
|
||||
Hand,
|
||||
Foundation0,
|
||||
Foundation1,
|
||||
Foundation2,
|
||||
Foundation3,
|
||||
Tableau0,
|
||||
Tableau1,
|
||||
Tableau2,
|
||||
@@ -20,6 +19,11 @@ pub enum KlondikePileId {
|
||||
Tableau5,
|
||||
Tableau6,
|
||||
Tableau7,
|
||||
Stock,
|
||||
Foundation0,
|
||||
Foundation1,
|
||||
Foundation2,
|
||||
Foundation3,
|
||||
}
|
||||
impl std::ops::Index<KlondikePileId> for KlondikeState {
|
||||
type Output = Pile;
|
||||
@@ -42,10 +46,41 @@ pub struct Klondike {
|
||||
state: KlondikeState,
|
||||
}
|
||||
impl Klondike {
|
||||
pub fn new(mut seed: Rng) -> Self {
|
||||
pub fn new(mut seed: Rng, config: KlondikeConfig) -> Self {
|
||||
// shuffle a new deck
|
||||
let mut deck = Stack::full_deck(0);
|
||||
use rand::seq::SliceRandom;
|
||||
deck.shuffle(&mut seed);
|
||||
unimplemented!()
|
||||
|
||||
// generate tableaus
|
||||
let [t0, t1, t2, t3, t4, t5, t6, t7] = core::array::from_fn(|i| {
|
||||
let stack = deck.split_off(i).into();
|
||||
let mut pile = Pile::new_face_down(stack);
|
||||
pile.push(deck.pop().unwrap());
|
||||
pile
|
||||
});
|
||||
|
||||
// stock is remaining cards
|
||||
let stock = Pile::new_face_down(deck);
|
||||
|
||||
let state = KlondikeState {
|
||||
piles: [
|
||||
t0,
|
||||
t1,
|
||||
t2,
|
||||
t3,
|
||||
t4,
|
||||
t5,
|
||||
t6,
|
||||
t7,
|
||||
stock,
|
||||
Pile::new(),
|
||||
Pile::new(),
|
||||
Pile::new(),
|
||||
Pile::new(),
|
||||
],
|
||||
};
|
||||
Self { config, state }
|
||||
}
|
||||
}
|
||||
impl Game for Klondike {
|
||||
|
||||
Reference in New Issue
Block a user