def handle_entry(self, comment, user, command_parts): logging.info('User [%s] entered to PIF [%s]', user, self.postId) deck = poker_util.new_deck() user_hand = list() for i in range(5): card = poker_util.deal_card(deck) user_hand.append(card) user_hand = poker_util.order_cards(user_hand) entry_details = dict() entry_details['CommentId'] = comment.id entry_details['UserHand'] = user_hand entry_details['HandScore'] = poker_util.hand_score(user_hand) self.pifEntries[user.name] = entry_details comment.reply( entry_template.format(user.name, poker_util.format_card(user_hand[0]), poker_util.format_card(user_hand[1]), poker_util.format_card(user_hand[2]), poker_util.format_card(user_hand[3]), poker_util.format_card(user_hand[4]), poker_util.determine_hand(user_hand))) comment.save()
def test_poker(): deck = poker_util.new_deck() tied_winners = list() curr_max_score = 0 shared_cards = list() for i in range(3): shared_cards.append(poker_util.deal_card(deck)) print('--------------------') print("Shared cards: {}".format(poker_util.order_cards(shared_cards))) while len(deck) > 2: hand = list() for card in shared_cards: hand.append(card) for i in range(2): hand.append(poker_util.deal_card(deck)) ordered = poker_util.order_cards(hand) print("{} - {} - {}".format(ordered, poker_util.determine_hand(hand), poker_util.hand_score(hand))) if poker_util.hand_score(ordered) > curr_max_score: tied_winners = list() tied_winners.append(ordered) curr_max_score = poker_util.hand_score(ordered) elif poker_util.hand_score(ordered) == curr_max_score: tied_winners.append(ordered) print('--------------------') if len(tied_winners) == 1: print("{} - {} - {}".format(tied_winners[0], poker_util.determine_hand(tied_winners[0]), poker_util.hand_score(tied_winners[0]))) else: print("{} hands tied for win: {} - {} - {}".format( len(tied_winners), tied_winners[0], poker_util.determine_hand(tied_winners[0]), poker_util.hand_score(tied_winners[0])))
def handle_entry(self, comment, user, command_parts): logging.info('User [%s] entered to PIF [%s]', user, self.postId) deck = self.pifOptions['Deck'] if len(deck) < 2: comment.reply( "Sorry, I'm out of cards. Time to wrap this thing up.") comment.save() self.finalize() return shared_cards = self.pifOptions['SharedCards'] user_hand = list() user_cards = list() for card in shared_cards: user_hand.append(card) for i in range(2): card = poker_util.deal_card(deck) user_cards.append(card) user_hand.append(card) user_hand = poker_util.order_cards(user_hand) # Gotta put the deck back with fewer cards self.pifOptions['Deck'] = deck entry_details = dict() entry_details['CommentId'] = comment.id entry_details['UserCards'] = user_cards entry_details['UserHand'] = user_hand entry_details['HandScore'] = poker_util.hand_score(user_hand) self.pifEntries[user.name] = entry_details comment.reply( entry_template.format(user.name, poker_util.format_card(user_cards[0]), poker_util.format_card(user_cards[1]), poker_util.format_card(user_hand[0]), poker_util.format_card(user_hand[1]), poker_util.format_card(user_hand[2]), poker_util.format_card(user_hand[3]), poker_util.format_card(user_hand[4]), poker_util.determine_hand(user_hand))) comment.save() if len(deck) < 2: self.finalize()
def generate_winner_comment(self): return winner_template.format( ' '.join([ poker_util.format_card(x) for x in self.pifOptions['FlopCards'] ]), poker_util.format_card(self.pifOptions['TurnCard']), poker_util.format_card(self.pifOptions['RiverCard']), self.pifWinner, ' '.join([ poker_util.format_card(x) for x in self.pifEntries[self.pifWinner]['BestHand'] ]), poker_util.determine_hand( self.pifEntries[self.pifWinner]['BestHand']), self.pifOptions['ExtraInfo'], )
def test_hands(): hands = list() royal_flush = [[10, '♥'], ['J', '♥'], ['Q', '♥'], ['K', '♥'], ['A', '♥']] hands.append(royal_flush) straight_flush_to_the_five = [[2, '♥'], [3, '♥'], [4, '♥'], [5, '♥'], ['A', '♥']] hands.append(straight_flush_to_the_five) straight_flush_to_the_six = [[2, '♥'], [3, '♥'], [4, '♥'], [5, '♥'], [6, '♥']] hands.append(straight_flush_to_the_six) four_of_a_kind = [[10, '♦'], [10, '♠'], [10, '♥'], [10, '♣'], ['K', '♥']] hands.append(four_of_a_kind) full_boat = [[10, '♦'], [10, '♠'], [10, '♥'], ['K', '♦'], ['K', '♥']] hands.append(full_boat) flush = [[2, '♥'], ['J', '♥'], ['Q', '♥'], ['K', '♥'], ['A', '♥']] hands.append(flush) straight = [[10, '♦'], ['J', '♥'], ['Q', '♥'], ['K', '♥'], ['A', '♥']] hands.append(straight) five_high_straight = [[2, '♦'], [3, '♥'], [4, '♥'], [5, '♥'], ['A', '♥']] hands.append(five_high_straight) six_high_straight = [[2, '♦'], [3, '♥'], [4, '♥'], [5, '♥'], [6, '♥']] hands.append(six_high_straight) trips = [[10, '♦'], [10, '♠'], [10, '♥'], ['Q', '♦'], ['K', '♥']] hands.append(trips) two_pair = [[2, '♦'], [10, '♠'], [10, '♥'], ['K', '♦'], ['K', '♥']] hands.append(two_pair) pair = [[2, '♦'], [4, '♠'], [6, '♥'], ['K', '♦'], ['K', '♥']] hands.append(pair) high_card = [[2, '♦'], [4, '♥'], [6, '♥'], [8, '♥'], ['K', '♥']] hands.append(high_card) low_ace_straight = [[2, '♦'], [3, '♥'], [4, '♥'], [5, '♥'], ['A', '♥']] hands.append(low_ace_straight) for hand in hands: print("{} - {} - {}".format(hand, poker_util.determine_hand(hand), poker_util.hand_score(hand)))
def generate_winner_comment(self): return winner_template.format( self.pifWinner, poker_util.determine_hand( self.pifEntries[self.pifWinner]['UserHand']))
|Redditor|PIFs| |:-|:-|""".format(history_days, pif_count, len(piffers))) for piffer in sorted_piffers: print("|u/{}|{}|".format(piffer[0], piffer[1])) print( """\nThere were {} entries across the {} PIFs. The top 10 most active PIF contestants were: |Redditor|Entries| |:-|:-|""".format(entry_count, pif_count)) for i in range(10): print("|u/{}|{}|".format(sorted_entrants[i][0], sorted_entrants[i][1])) print("\nWinningest Redditors:\n\n|Redditor|Wins|\n|:-|:-|") for pif_winner in sorted_winners: print("|u/{}|{}|".format(pif_winner[0], pif_winner[1])) print( "\nMost popular PIF types:\n\n|PIF Type|Count|Entries per PIF|\n|:-|:-|:-|" ) for pif_type in sorted_pif_types: avg_entries = 0 if pif_type[1] > 0: avg_entries = round(pif_type_entries[pif_type[0]] / pif_type[1], 2) print("|{}|{}|{}|".format(pif_type[0], pif_type[1], avg_entries)) print("\nBest poker hand: {} with {}".format( best_poker_hand_user, poker_util.determine_hand(best_poker_hand)))