From: Geoffrey Allott Date: Thu, 8 Jun 2023 08:18:59 +0000 (+0100) Subject: handle dealer PutInBox correctly X-Git-Url: https://git.pointlesshacks.com/?a=commitdiff_plain;h=23f8cac244fe61e5e3cb7bfcb29c5a2fab809257;p=pokerwave.git handle dealer PutInBox correctly --- diff --git a/src/game/cribbage/mod.rs b/src/game/cribbage/mod.rs index 1dcd1ce..d813880 100644 --- a/src/game/cribbage/mod.rs +++ b/src/game/cribbage/mod.rs @@ -290,6 +290,11 @@ impl Game for Cribbage { self.state = State::Choosing; Ok(()) } + (State::Dealing, Action::PutInBox { card: Some(card) }) => { + self.deck.remove(&card); + self.box_cards.insert(card); + Ok(()) + } (State::Choosing, Action::PutInBox { card: Some(card) }) => { if let Some(hand) = self.hands.get_mut(&username) { hand.remove(&card); @@ -540,7 +545,7 @@ mod tests { let mut game = Cribbage::new(0, settings, seed); for action in actions { match action.action { - Action::Join { .. } | Action::PutInBox { .. } | Action::PlayCard { .. } | Action::Pass => { + Action::Join { .. } | Action::PutInBox { .. } | Action::PlayCard { .. } | Action::Pass if game.state != State::Dealing => { let validated = game.validate_action(action.clone()).unwrap(); assert_eq!(ValidatedUserAction(action), validated); game.take_action(validated).unwrap(); @@ -2264,4 +2269,43 @@ mod tests { test_game(actions, settings, seed); } + + #[test] + fn three_player_cribbage() { + let actions = r#"[ + {"timestamp":1686202473466,"username":"Geoff","action":{"action":"Join","seat":0,"chips":0}}, + {"timestamp":1686202505067,"username":"Aga","action":{"action":"Join","seat":1,"chips":0}}, + {"timestamp":1686202533315,"username":"Peter","action":{"action":"Join","seat":2,"chips":0}}, + {"timestamp":1686202533316,"username":"Aga","action":{"action":"NextToDeal"}}, + {"timestamp":1686202533316,"username":"Peter","action":{"action":"ReceiveCard","card":{"rank":"Five","suit":"Hearts"}}}, + {"timestamp":1686202533317,"username":"Geoff","action":{"action":"ReceiveCard","card":{"rank":"Jack","suit":"Diamonds"}}}, + {"timestamp":1686202533318,"username":"Aga","action":{"action":"ReceiveCard","card":{"rank":"Five","suit":"Spades"}}}, + {"timestamp":1686202533319,"username":"Peter","action":{"action":"ReceiveCard","card":{"rank":"Jack","suit":"Hearts"}}}, + {"timestamp":1686202533319,"username":"Geoff","action":{"action":"ReceiveCard","card":{"rank":"Nine","suit":"Spades"}}}, + {"timestamp":1686202533320,"username":"Aga","action":{"action":"ReceiveCard","card":{"rank":"Three","suit":"Clubs"}}}, + {"timestamp":1686202533320,"username":"Peter","action":{"action":"ReceiveCard","card":{"rank":"Four","suit":"Hearts"}}}, + {"timestamp":1686202533320,"username":"Geoff","action":{"action":"ReceiveCard","card":{"rank":"Queen","suit":"Diamonds"}}}, + {"timestamp":1686202533321,"username":"Aga","action":{"action":"ReceiveCard","card":{"rank":"Seven","suit":"Clubs"}}}, + {"timestamp":1686202533321,"username":"Peter","action":{"action":"ReceiveCard","card":{"rank":"Eight","suit":"Spades"}}}, + {"timestamp":1686202533321,"username":"Geoff","action":{"action":"ReceiveCard","card":{"rank":"Five","suit":"Clubs"}}}, + {"timestamp":1686202533322,"username":"Aga","action":{"action":"ReceiveCard","card":{"rank":"Three","suit":"Diamonds"}}}, + {"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":"PutInBox","card":{"rank":"Nine","suit":"Clubs"}}}, + {"timestamp":1686202533324,"username":"Aga","action":{"action":"EndDeal"}} + ]"#; + + let actions = serde_json::from_str(actions).unwrap(); + + let settings = r#"{"format":"Cribbage","title":"Based Business","max_players":3,"target_score":121,"start_time":null}"#; + let settings = serde_json::from_str(settings).unwrap(); + let seed = r#"{"rng":"ChaCha8","seed":"983c249eac8299ca583f8826898e0e1eb87b70787fb39235bc4953a92c28db41"}"#; + let seed = serde_json::from_str(seed).unwrap(); + + test_game(actions, settings, seed); + } }