deal 5 cards for 3 and 4-player cribbage
authorGeoffrey Allott <geoffrey@allott.email>
Wed, 14 Jun 2023 10:37:43 +0000 (11:37 +0100)
committerGeoffrey Allott <geoffrey@allott.email>
Wed, 14 Jun 2023 10:37:43 +0000 (11:37 +0100)
src/game/cribbage/.mod.rs.swp [new file with mode: 0644]
src/game/cribbage/mod.rs

diff --git a/src/game/cribbage/.mod.rs.swp b/src/game/cribbage/.mod.rs.swp
new file mode 100644 (file)
index 0000000..fd2e403
Binary files /dev/null and b/src/game/cribbage/.mod.rs.swp differ
index fc7dcee6936fc7f064a20ec3a2d1a92e4338d9f7..e4e68fc7b766022c00ec37b37b1eaf17f8f3ad27 100644 (file)
@@ -100,7 +100,13 @@ impl Cribbage {
     }
 
     fn all_hands_dealt(&self) -> bool {
-        self.hands.values().map(CardSet::len).all(|len| len == 6)
+        let hand_size = match self.hands.len() {
+            2 => 6,
+            3 => 5,
+            4 => 5,
+            _ => 6,
+        };
+        self.hands.values().map(CardSet::len).all(|len| len == hand_size)
     }
 
     fn pegging_total(&self) -> u32 {
@@ -2292,10 +2298,7 @@ mod tests {
             {"timestamp":1686202533322,"username":"Peter","action":{"action":"ReceiveCard","card":{"rank":"King","suit":"Clubs"}}},
             {"timestamp":1686202533322,"username":"Geoff","action":{"action":"ReceiveCard","card":{"rank":"Six","suit":"Clubs"}}},
             {"timestamp":1686202533323,"username":"Aga","action":{"action":"ReceiveCard","card":{"rank":"Four","suit":"Diamonds"}}},
-            {"timestamp":1686202533323,"username":"Peter","action":{"action":"ReceiveCard","card":{"rank":"Ten","suit":"Clubs"}}},
-            {"timestamp":1686202533323,"username":"Geoff","action":{"action":"ReceiveCard","card":{"rank":"Nine","suit":"Diamonds"}}},
-            {"timestamp":1686202533324,"username":"Aga","action":{"action":"ReceiveCard","card":{"rank":"Ace","suit":"Hearts"}}},
-            {"timestamp":1686202533324,"username":"Aga","action":{"action":"DealBox","card":{"rank":"Nine","suit":"Clubs"}}},
+            {"timestamp":1686202533324,"username":"Aga","action":{"action":"DealBox","card":{"rank":"Ten","suit":"Clubs"}}},
             {"timestamp":1686202533324,"username":"Aga","action":{"action":"EndDeal"}}
         ]"#;