Welcome, guest | Sign In | My Account | Store | Cart
#!/usr/bin/env python3
import collections
import itertools
import random
import sys
suit_list = ("Hearts", "Spades", "Diamonds", "Clubs")
numeral_list = ("2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace")
class card:
    def __init__(self, numeral, suit):
        self.numeral = numeral
        self.suit = suit
        self.card = self.numeral, self.suit
    def __repr__(self):
        return self.numeral + "-" + self.suit
class deck(set):
    def __init__(self):
        for numeral, suit in itertools.product(numeral_list, suit_list):
            self.add(card(numeral, suit))
    def get_card(self):
        a_card = random.sample(self, 1)[0]
        self.remove(a_card)
        return a_card
    def get_hand(self, number_of_cards=5):
        return_list = list()
        for i in range(number_of_cards):
            return_list.append(self.get_card())
        return return_list

for i in range(10000):
    print()
    my_deck = deck()
    my_hand = my_deck.get_hand()
    print(my_hand)
    numeral_dict = collections.defaultdict(int)
    suit_dict = collections.defaultdict(int)
    for my_card in my_hand:
        numeral_dict[my_card.numeral] += 1
        suit_dict[my_card.suit] += 1
    if len(numeral_dict) == 4:
        print("One pair.")
    elif len(numeral_dict) == 3:
        if 3 in numeral_dict.values():
            print("Three-of-a-kind.")
        else:
            print("Two pair.")
    elif len(numeral_dict) == 2:
        if 2 in numeral_dict.values():
            print("Full house.")
        else:
            print("Four-of-a-kind.")
    elif len(suit_dict) == 1:
        print("Flush.")
    else:
        min_numeral = min([numeral_list.index(x) for x in numeral_dict.keys()])
        max_numeral = max([numeral_list.index(x) for x in numeral_dict.keys()])
        if int(max_numeral) - int(min_numeral) == 4:
            print("Straight.")
        # Ace can be low
        low_straight = set(("Ace", "2", "3", "4", "5"))
        if not set(numeral_dict.keys()).difference(low_straight):
            print("Straight.")

History