From 09822a98a2b947ff471eb8056444dbf561c8eda3 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Thu, 13 Jul 2023 12:20:27 -0700 Subject: [PATCH 1/1] Deck --- src/lib.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index a5148a0..b7dc954 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,33 @@ use rand::Rng; pub const NUM_RANKS: u8 = 13; +pub const NUM_SUITS: u8 = 4; +pub const NUM_CARDS: u8 = NUM_RANKS * NUM_SUITS; #[derive(Clone, Copy, Eq, PartialEq)] pub struct Rank(u8); +#[derive(Clone, Copy, Eq, PartialEq)] +pub struct Suit(u8); + +#[derive(Clone, Copy, Eq, PartialEq)] +pub struct Card(u8); +impl Card { + #[must_use] + pub fn rank(&self) -> Rank { + Rank(self.0 >> 2) + } + #[must_use] + pub fn suit(&self) -> Suit { + Suit(self.0 & 3) + } +} + +#[must_use] +pub fn deck() -> Vec { + (0..NUM_CARDS).map(Card).collect() +} + #[derive(Clone, Copy)] pub struct PathLength(Rank); @@ -61,4 +84,9 @@ mod tests { } assert!(pli.reveal_random(length).is_none()); } + + #[test] + fn test_deck() { + let _d = deck(); + } } -- 2.44.1