seed_from_u64 (#7)

Closes #5

Reviewed-on: #7
Co-authored-by: Rhys Lloyd <krakow20@gmail.com>
Co-committed-by: Rhys Lloyd <krakow20@gmail.com>
This commit was merged in pull request #7.
This commit is contained in:
2026-05-18 19:17:11 +00:00
committed by Quaternions
parent 25760d19a1
commit a28a965d12
6 changed files with 21 additions and 10 deletions
+7 -5
View File
@@ -1,4 +1,4 @@
pub type Rng = rand::rngs::ThreadRng;
pub type Rng = rand::rngs::StdRng;
use card_game::{Card, Game, Pile, Rank, Stack};
@@ -532,14 +532,16 @@ pub struct Klondike {
state: KlondikeState,
}
impl Klondike {
pub fn new_random() -> Self {
Self::new(Rng::default())
pub fn with_seed(seed: u64) -> Self {
use rand::SeedableRng;
let rng = Rng::seed_from_u64(seed);
Self::with_rng(rng)
}
pub fn new(mut seed: Rng) -> Self {
pub fn with_rng(mut rng: Rng) -> Self {
// shuffle a new deck
let mut deck = Stack::full_deck(card_game::Deck::Deck1);
use rand::seq::SliceRandom;
deck.shuffle(&mut seed);
deck.shuffle(&mut rng);
let mut deck = deck.into_iter();
// generate tableaus