From: Geoffrey Allott Date: Sat, 27 May 2023 13:59:28 +0000 (+0100) Subject: fix some more issues with betting X-Git-Url: https://git.pointlesshacks.com/?a=commitdiff_plain;h=54cccf2651deec99788a9da8b88b4b787b9999a3;p=pokerwave.git fix some more issues with betting --- diff --git a/src/game/poker/holdem.rs b/src/game/poker/holdem.rs index cc10f5a..f0b8c47 100644 --- a/src/game/poker/holdem.rs +++ b/src/game/poker/holdem.rs @@ -424,10 +424,11 @@ impl Game for TexasHoldEm { *self.bets.entry(username).or_default() += chips; *self.committed.entry(username).or_default() += chips; *self.stacks.entry(username).or_default() -= chips; - self.active = self.seats.player_after_where(username, |username| self.in_hand.contains(&username)); self.state = State::PreFlopBetting; if self.betting_round_completed() { - self.state = State::DealingFlop; + self.advance_betting_round()?; + } else { + self.active = self.seats.player_after_where(username, |username| self.is_able_to_bet(username)); } Ok(()) } @@ -437,7 +438,8 @@ impl Game for TexasHoldEm { *self.stacks.entry(username).or_default() -= chips; if self.betting_round_completed() { self.advance_betting_round()?; - } else { self.active = self.seats.player_after_where(username, |username| self.is_able_to_bet(username)); + } else { + self.active = self.seats.player_after_where(username, |username| self.is_able_to_bet(username)); } Ok(()) } @@ -1881,4 +1883,65 @@ mod tests { test_game(actions, settings, seed); } + + #[test] + fn very_small_stack_game() { + let actions = r#"[ + {"timestamp":1685137578856,"username":"Peter","action":{"action":"Join","seat":0,"chips":7}}, + {"timestamp":1685137605395,"username":"Geoff","action":{"action":"Join","seat":1,"chips":7}}, + {"timestamp":1685137634338,"username":"Aga","action":{"action":"Join","seat":2,"chips":7}}, + {"timestamp":1685137634339,"username":"Geoff","action":{"action":"NextToDeal"}}, + {"timestamp":1685137634339,"username":"Aga","action":{"action":"ReceiveCard","card":{"rank":"Two","suit":"Spades"}}}, + {"timestamp":1685137634339,"username":"Peter","action":{"action":"ReceiveCard","card":{"rank":"Ace","suit":"Clubs"}}}, + {"timestamp":1685137634340,"username":"Geoff","action":{"action":"ReceiveCard","card":{"rank":"Jack","suit":"Spades"}}}, + {"timestamp":1685137634340,"username":"Aga","action":{"action":"ReceiveCard","card":{"rank":"Seven","suit":"Spades"}}}, + {"timestamp":1685137634340,"username":"Peter","action":{"action":"ReceiveCard","card":{"rank":"Queen","suit":"Clubs"}}}, + {"timestamp":1685137634341,"username":"Geoff","action":{"action":"ReceiveCard","card":{"rank":"Five","suit":"Hearts"}}}, + {"timestamp":1685137634341,"username":"Geoff","action":{"action":"EndDeal"}}, + {"timestamp":1685137634341,"username":"Aga","action":{"action":"PostBlind","chips":7}}, + {"timestamp":1685137634342,"username":"Peter","action":{"action":"PostBlind","chips":7}}, + {"timestamp":1685137645517,"username":"Geoff","action":{"action":"Fold"}}, + {"timestamp":1685137645518,"username":"Aga","action":{"action":"RevealCard","card":{"rank":"Two","suit":"Spades"}}}, + {"timestamp":1685137645518,"username":"Aga","action":{"action":"RevealCard","card":{"rank":"Seven","suit":"Spades"}}}, + {"timestamp":1685137645518,"username":"Peter","action":{"action":"RevealCard","card":{"rank":"Queen","suit":"Clubs"}}}, + {"timestamp":1685137645519,"username":"Peter","action":{"action":"RevealCard","card":{"rank":"Ace","suit":"Clubs"}}}, + {"timestamp":1685137645519,"username":"Geoff","action":{"action":"CommunityCard","card":{"rank":"Eight","suit":"Clubs"}}}, + {"timestamp":1685137645519,"username":"Geoff","action":{"action":"CommunityCard","card":{"rank":"King","suit":"Spades"}}}, + {"timestamp":1685137645519,"username":"Geoff","action":{"action":"CommunityCard","card":{"rank":"Seven","suit":"Clubs"}}}, + {"timestamp":1685137645520,"username":"Geoff","action":{"action":"CommunityCard","card":{"rank":"Seven","suit":"Hearts"}}}, + {"timestamp":1685137645520,"username":"Geoff","action":{"action":"CommunityCard","card":{"rank":"Nine","suit":"Clubs"}}}, + {"timestamp":1685137645520,"username":"Peter","action":{"action":"WinHand","chips":14,"hand":"Flush, AQ987"}}, + {"timestamp":1685137645520,"username":"Aga","action":{"action":"KnockedOut"}}, + {"timestamp":1685137645521,"username":"Aga","action":{"action":"NextToDeal"}}, + {"timestamp":1685137645521,"username":"Peter","action":{"action":"ReceiveCard","card":{"rank":"Ten","suit":"Clubs"}}}, + {"timestamp":1685137645521,"username":"Geoff","action":{"action":"ReceiveCard","card":{"rank":"Three","suit":"Diamonds"}}}, + {"timestamp":1685137645522,"username":"Peter","action":{"action":"ReceiveCard","card":{"rank":"Two","suit":"Spades"}}}, + {"timestamp":1685137645522,"username":"Geoff","action":{"action":"ReceiveCard","card":{"rank":"Two","suit":"Diamonds"}}}, + {"timestamp":1685137645523,"username":"Aga","action":{"action":"EndDeal"}}, + {"timestamp":1685137645523,"username":"Peter","action":{"action":"PostBlind","chips":14}}, + {"timestamp":1685137645523,"username":"Geoff","action":{"action":"PostBlind","chips":7}}, + {"timestamp":1685137645523,"username":"Geoff","action":{"action":"RevealCard","card":{"rank":"Two","suit":"Diamonds"}}}, + {"timestamp":1685137645524,"username":"Geoff","action":{"action":"RevealCard","card":{"rank":"Three","suit":"Diamonds"}}}, + {"timestamp":1685137645524,"username":"Peter","action":{"action":"RevealCard","card":{"rank":"Two","suit":"Spades"}}}, + {"timestamp":1685137645524,"username":"Peter","action":{"action":"RevealCard","card":{"rank":"Ten","suit":"Clubs"}}}, + {"timestamp":1685137645524,"username":"Aga","action":{"action":"CommunityCard","card":{"rank":"Four","suit":"Diamonds"}}}, + {"timestamp":1685137645525,"username":"Aga","action":{"action":"CommunityCard","card":{"rank":"Three","suit":"Clubs"}}}, + {"timestamp":1685137645525,"username":"Aga","action":{"action":"CommunityCard","card":{"rank":"Five","suit":"Clubs"}}}, + {"timestamp":1685137645525,"username":"Aga","action":{"action":"CommunityCard","card":{"rank":"Six","suit":"Clubs"}}}, + {"timestamp":1685137645526,"username":"Aga","action":{"action":"CommunityCard","card":{"rank":"Ace","suit":"Clubs"}}}, + {"timestamp":1685137645526,"username":"Peter","action":{"action":"WinHand","chips":21,"hand":"Flush, AT653"}}, + {"timestamp":1685137645526,"username":"Geoff","action":{"action":"KnockedOut"}}, + {"timestamp":1685137645526,"username":"Peter","action":{"action":"WinGame"}} + ]"#; + + let actions = serde_json::from_str(actions).unwrap(); + + let settings = r#"{"format":"TexasHoldEm","title":"Quality Adventure","max_players":3,"small_blind":25,"starting_stack":7,"round_length":null,"tournament_length":null,"action_timeout":null,"start_time":null,"hide_cards":false}"#; + let settings = serde_json::from_str(settings).unwrap(); + + let seed = r#"{"rng":"ChaCha20","seed":"71358486a2dfd6efe046cc39d7a0f1b425caab7fe6ae92fa487c927783edbf5f"}"#; + let seed = serde_json::from_str(seed).unwrap(); + + test_game(actions, settings, seed); + } }