3 pub const NUM_RANKS: u8 = 13;
4 pub const NUM_SUITS: u8 = 4;
5 pub const NUM_CARDS: u8 = NUM_RANKS * NUM_SUITS;
7 #[derive(Clone, Copy, Eq, PartialEq)]
10 #[derive(Clone, Copy, Eq, PartialEq)]
13 #[derive(Clone, Copy, Eq, PartialEq)]
17 pub fn rank(&self) -> Rank {
21 pub fn suit(&self) -> Suit {
27 pub fn deck() -> Vec<Card> {
28 (0..NUM_CARDS).map(Card).collect()
31 #[derive(Clone, Copy)]
32 pub struct PathLength(Rank);
34 #[derive(Clone, Copy, Default)]
35 pub struct PathLengthInfo(u16);
38 pub fn is_showing(&self, i: Rank) -> bool {
39 (self.0 >> i.0) & 1 == 1
41 fn reveal(&mut self, i: Rank) {
44 pub fn reveal_random(&mut self, true_length: PathLength) -> Option<Rank> {
45 let showing = u8::try_from(self.0.count_ones()).expect("There aren't that many bits");
46 let not_showing = NUM_RANKS - showing;
51 let mut show = rand::thread_rng().gen_range(0..not_showing - 1);
52 for i in 0..NUM_RANKS {
54 if !self.is_showing(r) && r != true_length.0 {
71 fn path_length_info_random_reveal() {
72 let length = PathLength(Rank(7));
73 let mut pli = PathLengthInfo::default();
75 let old_pli = PathLengthInfo::clone(&pli);
76 match pli.reveal_random(length) {
77 None => panic!("Nothing revealed?"),
79 assert!(!old_pli.is_showing(r));
80 assert!(pli.is_showing(r));
83 assert_eq!(pli.0.count_ones(), 1 + old_pli.0.count_ones());
85 assert!(pli.reveal_random(length).is_none());