From: Scott Worley Date: Thu, 13 Jul 2023 19:20:27 +0000 (-0700) Subject: Deck X-Git-Url: http://git.scottworley.com/pluta-lesnura/commitdiff_plain/09822a98a2b947ff471eb8056444dbf561c8eda3?hp=0714539db698534ec5c34e4ee7d370439e293cac Deck --- 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(); + } }