3 pub const NUM_RANKS: u8 = 13;
5 #[derive(Clone, Copy, Eq, PartialEq)]
9 pub struct PathLength(Rank);
11 #[derive(Clone, Copy, Default)]
12 pub struct PathLengthInfo(u16);
15 pub fn is_showing(&self, i: Rank) -> bool {
16 (self.0 >> i.0) & 1 == 1
18 fn reveal(&mut self, i: Rank) {
21 pub fn reveal_random(&mut self, true_length: PathLength) -> Option<Rank> {
22 let showing = u8::try_from(self.0.count_ones()).expect("There aren't that many bits");
23 let not_showing = NUM_RANKS - showing;
28 let mut show = rand::thread_rng().gen_range(0..not_showing - 1);
29 for i in 0..NUM_RANKS {
31 if !self.is_showing(r) && r != true_length.0 {
48 fn path_length_info_random_reveal() {
49 let length = PathLength(Rank(7));
50 let mut pli = PathLengthInfo::default();
52 let old_pli = PathLengthInfo::clone(&pli);
53 match pli.reveal_random(length) {
54 None => panic!("Nothing revealed?"),
56 assert!(!old_pli.is_showing(r));
57 assert!(pli.is_showing(r));
60 assert_eq!(pli.0.count_ones(), 1 + old_pli.0.count_ones());
62 assert!(pli.reveal_random(length).is_none());