def _action_if_game_finish(self): if self._is_complete_game(): #for player in self._room_status.user_playing_list: winners = [] if len(self._room_status.user_round_list) == 1: winner = self._room_status.user_round_list[0] winners.append(winner) elif len(self._room_status.user_round_list) >= 2: poker_hands = dict() player_name = self._room_status.user_round_list[0] cards = self._game.get_player(player_name).get_card_set() max_hand = get_PokerHand_from_list(cards + self._room_status.saving_cards) poker_hands[player_name] = max_hand for player in self._room_status.user_round_list[1:]: cards = self._game.get_player(player).get_card_set() poker_hand = get_PokerHand_from_list(cards + self._room_status.saving_cards) poker_hands[player] = poker_hand max_hand = max(max_hand, poker_hand) for player in poker_hands: poker_hand = poker_hands[player] if poker_hand == max_hand: winners.append(player) print player, poker_hand.mean_cards if winners: """this game only has 2 players, we will implement >2 players in the future""" total_pot = self._get_pot() if len(winners) == 1: winner = winners[0] self._room_status.player_stakes[winner] += min(total_pot, self._room_status.pot_contribution[winner]*2) if self._room_status.playing_status == STATUS_SHOWDOWN: mean_cards = [card.value for card in poker_hands[winner].mean_cards] self._msg_delivery.broadcast_poker_winner(winner, mean_cards) elif len(winners) == 2: """return money""" for winner in winners: self._room_status.player_stakes[winner] += self._room_status.pot_contribution[winner] if self._room_status.playing_status == STATUS_SHOWDOWN: mean_cards = [card.value for card in poker_hands[winner].mean_cards] self._msg_delivery.broadcast_poker_winner(winner, mean_cards) self._broad_cast_stakes() LOGGER.debug('Completed a game.') #print self._room_status.pot_contribution #print self._room_status.player_stakes """give all player 10 seconds extra time""" for player_username in self._room_status.user_list: player = self._game.get_player(player_username) if player: player.delay_active_time(10) if not self._is_eliminated(): """continue game""" self._preflop_round() #self.stop_game() #self.start_game() else: self.stop_match()
def testPokerHandHighCard(self): hand1 = get_PokerHand_from_list([1, 9, 18, 25, 35]) hand2 = get_PokerHand_from_list([2, 10, 19, 26, 34]) self.assertEqual(hand1.hand, Hand.HIGH_CARD) self.assertEqual(hand2.hand, Hand.HIGH_CARD) self.assertEqual(hand1, hand2) hand2 = get_PokerHand_from_list([10, 19, 26, 34, 50]) self.assertEqual(hand1.hand, Hand.HIGH_CARD) self.assertEqual(hand2.hand, Hand.HIGH_CARD) self.assertGreater(hand1, hand2)
def testPokerHand7CardsGeneric(self): for _count in xrange(10000): hand1 = get_PokerHand_from_list([random.randint(0,51) for _ in range(7)]) hand2 = get_PokerHand_from_list([random.randint(0,51) for _ in range(7)]) self.assertTrue(len(hand1.mean_cards)==5) self.assertTrue(len(hand2.mean_cards)==5) if hand1 < hand2: self.assertLessEqual(hand1.hand, hand2.hand) elif hand1 > hand2: self.assertGreaterEqual(hand1.hand, hand2.hand) elif hand1 == hand2: self.assertEqual(hand1.hand, hand2.hand)
def testPokerHandStraight(self): hand1 = get_PokerHand_from_list([1, 5, 9, 14, 18]) self.assertTrue(len(hand1.mean_cards) == 5) self.assertEqual(hand1.hand, Hand.STRAIGHT) hand1 = get_PokerHand_from_list([5, 9, 14, 18, 20]) self.assertTrue(len(hand1.mean_cards) == 5) self.assertEqual(hand1.hand, Hand.STRAIGHT) hand1 = get_PokerHand_from_list([1, 50, 47, 43, 36]) self.assertTrue(len(hand1.mean_cards) == 5) self.assertEqual(hand1.hand, Hand.STRAIGHT) hand1 = get_PokerHand_from_list([1, 50, 47, 48, 43, 36]) self.assertTrue(len(hand1.mean_cards) == 5) self.assertEqual(hand1.hand, Hand.STRAIGHT)
def testPokerHandStraightFlush(self): hand1 = get_PokerHand_from_list([4, 8, 12, 16, 20, 24]) self.assertEqual(hand1.hand, Hand.STRAIGHT_FLUSH)
def testPokerHandFourOfAKind(self): hand1 = get_PokerHand_from_list([4, 5, 6, 7, 19, 18, 30]) self.assertEqual(hand1.hand, Hand.FOUR_OF_A_KIND)
def testPokerHandFullHouse(self): hand1 = get_PokerHand_from_list([4, 5, 6, 19, 18, 30, 38]) self.assertEqual(hand1.hand, Hand.FULL_HOUSE)
def testPokerHandFlush(self): hand1 = get_PokerHand_from_list([4, 8, 12, 15, 20, 28]) self.assertEqual(hand1.hand, Hand.FLUSH)
def testPokerHandTwoPair(self): hand1 = get_PokerHand_from_list([1, 2, 9, 10, 18, 25]) self.assertEqual(hand1.hand, Hand.TWO_PAIR)
def testPokerHandOnePair(self): hand1 = get_PokerHand_from_list([1, 2, 9, 18, 25, 40]) self.assertEqual(hand1.hand, Hand.ONE_PAIR)