示例#1
0
 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()
示例#2
0
 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)
示例#3
0
 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)    
示例#4
0
 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)
示例#5
0
 def testPokerHandStraightFlush(self):
     hand1 = get_PokerHand_from_list([4, 8, 12, 16, 20, 24])
     self.assertEqual(hand1.hand, Hand.STRAIGHT_FLUSH)
示例#6
0
 def testPokerHandFourOfAKind(self):
     hand1 = get_PokerHand_from_list([4, 5, 6, 7, 19, 18, 30])
     self.assertEqual(hand1.hand, Hand.FOUR_OF_A_KIND)
示例#7
0
 def testPokerHandFullHouse(self):
     hand1 = get_PokerHand_from_list([4, 5, 6, 19, 18, 30, 38])
     self.assertEqual(hand1.hand, Hand.FULL_HOUSE)
示例#8
0
 def testPokerHandFlush(self):
     hand1 = get_PokerHand_from_list([4, 8, 12, 15, 20, 28])
     self.assertEqual(hand1.hand, Hand.FLUSH)
示例#9
0
 def testPokerHandTwoPair(self):
     hand1 = get_PokerHand_from_list([1, 2, 9, 10, 18, 25])
     self.assertEqual(hand1.hand, Hand.TWO_PAIR)
示例#10
0
 def testPokerHandOnePair(self):        
     hand1 = get_PokerHand_from_list([1, 2, 9, 18, 25, 40])
     self.assertEqual(hand1.hand, Hand.ONE_PAIR)