コード例 #1
0
    def probability_of_combinations(deck):

        num_of_hands = 0
        dic_of_combinations = {
            "Straight flush": 0,
            "Four of a kind": 0,
            "Full house": 0,
            "Flush": 0,
            "Straight": 0,
            "Three of a kind": 0,
            "Two pairs": 0,
            "Pair": 0,
            "No combinations": 0
        }
        for _ in range(60000):
            deck = Deck()
            deck.shuffle()

            for i in range(10):
                hand = PokerHand()
                num_of_hands += 1
                deck.move_cards(hand, 5)
                hand.sort()
                """print(hand)
                print(hand.classify())
                print(" ")"""
                dic_of_combinations[hand.classify()] += 1

        for key in dic_of_combinations:
            print(key, float(dic_of_combinations[key] / num_of_hands * 100))
        return None
コード例 #2
0
def test(n, n_hands=1, n_cards=7):
    """test shuffles a deck of cards, divides it into hands, classifies the
    hands, and counts the number of times various classifications appear.
    n is total number of trials
    n_hands is number of hands dealt per trial
    n_cards is number of cards per hand
    """
    hist = {
        "High Card": 0,
        "Pair": 0,
        "Two Pair": 0,
        "Three of a Kind": 0,
        "Straight": 0,
        "Flush": 0,
        "Full House": 0,
        "Four of a Kind": 0,
        "Straight Flush": 0,
        "Royal Flush": 0
    }

    for i in range(n):
        deck = Deck()
        deck.shuffle()
        for j in range(n_hands):
            hand = PokerHand()
            deck.move_cards(hand, 7)
            hist[hand.classify()] += 1
    ratios = {}
    check = 0
    for h in hist.keys():
        ratios[h] = hist[h] / (n * n_hands)
        check += hist[h]
    if check != n * n_hands:
        return ("Error with number of hands recorded: %g" % check)
    return ratios
コード例 #3
0
 def poker_stats(n):
     dico = dict()
     for i in range(n):
         deck = Deck()
         deck.shuffle()
         for i in range(7):
             hand = PokerHand()
             deck.move_cards(hand, 7)
             hand.classify()
             dico[hand.label]=dico.get(hand.label, 0)+(1/(7*n)*100)
     print(sorted(dico.items(), key=lambda x: -x[1]))
コード例 #4
0
def single_run(hands={}):
    deck = Deck()
    deck.shuffle()

    # deal the cards and classify the hands
    for i in range(7):
        hand = PokerHand()
        deck.move_cards(hand, 7)
        hand.sort()
        classification = str(hand.classify())
        hands[classification] = hands.get(classification, 0) + 1

    return hands
コード例 #5
0
def get_classDict():
    deck = Deck()
    deck.shuffle()
    handList = []
    for _ in range(7):
        hand = PokerHand()
        deck.move_cards(hand, 7)
        handList.append(hand)

    classDict = {}
    for hand in handList:
        hand.classify()
        classDict[hand.label] = classDict.get(hand.label, 0) + 1
    return classDict
コード例 #6
0
ファイル: PokerHand.py プロジェクト: juraj80/pokerSimulation
def game(handSize, players):
    deck = Deck()
    deck.shuffle()
    hand_labels = []
    for i in range(players):
        hand = PokerHand()
        deck.move_cards(hand, handSize)
        hand.sort()
        hand.classify()
        hand_labels.append(hand.label)
    label_dict = dict()
    for label in hand_labels:
        label_dict[label] = label_dict.get(label, 0) + 1
    return (label_dict)
コード例 #7
0
def statistics():
    hands = {}
    iterations = 500
    number_of_hands = 7
    for j in range(iterations):
        deck = Deck()
        deck.shuffle()
        for i in range(number_of_hands):
            hand = PokerHand()
            deck.move_cards(hand, 7)
            #print(hand)
            #print('')
            hand.classify()
            hands[hand.label] = hands.get(hand.label, 0) + 1
    for key in sorted(hands):
        print("Probability of a %s is %.3f%%" % (key, hands[key] / (iterations * number_of_hands) * 100))
コード例 #8
0
        else:
            return False

    def has_three_of_a_kind(self):
        self.rank_hist()
        i = 0
        for val in self.ranks.values():
            if val == 3:
                i += 1
        if i == 1:
            return True
        else:
            return False


if __name__ == '__main__':
    # make a deck
    deck = Deck()
    deck.shuffle()

    # deal the cards and classify the hands
    for i in range(7):
        hand = PokerHand()
        deck.move_cards(hand, 5)
        hand.sort()
        print(hand)
        print("Has flush:", hand.has_flush())
        print("Has a pair:", hand.has_pair())
        print("Has two pairs:", hand.has_pair(num=2))
        print('')
コード例 #9
0
        for val in self.ranks.values():
            if val >= 2:
                n += 1
        return n >= 2

    def has_three_of_a_kind(self):
        self.rank_hist()
        for val in self.ranks.values():
            if val >= 3:
                return True
        return False

    def has_straight(self):
        


if __name__ == '__main__':
    # make a deck
    deck = Deck()
    deck.shuffle()

    # deal the cards and classify the hands
    for i in range(7):
        hand = PokerHand()
        deck.move_cards(hand, 7)
        hand.sort()
        print(hand)
        print(hand.has_flush())
        print('')

コード例 #10
0
ファイル: ex18_3.py プロジェクト: uwais-rebel/TP_solutions
        '''
		straight: five cards with ranks in sequence
		
		flush: five cards with the same suit
		'''
        label = [
            'pair', 'two pair', 'three of a kind', 'striaght', 'flush',
            'full house', 'four of a kind', 'straight flush'
        ]


if __name__ == '__main__':
    # make a deck
    deck = Deck()
    deck.shuffle()

    # deal the cards and classify the hands
    h = PokerHand()
    deck.move_cards(h, 10)
    h.suit_hist()
    print(h)
    '''
	for i in range(7):
		hand = PokerHand()
		deck.move_cards(hand, 7)
		hand.suit_hist
		hand.sort()
		print(hand)
		print(hand.has_flush())
		print('')
	'''
コード例 #11
0
        return hand

if __name__ == '__main__':
    num_decks = int(input('How Many Decks to Shuffle?')) # Shuffle 1,000+ decks for highest accuracy
    num_hands = int(input('How Many Hands to Deal?')) # usually deal 7 hands
    total_hands = num_decks * num_hands
    prob_hist = {}

    for i in range(num_decks):
        deck = Deck()
        deck.shuffle()

    # deal the cards and classify the hands
        for i in range(num_hands):
            hand = PokerHand()
            deck.move_cards(hand, num_hands)
            hand.sort()
            hand.classify()
            # print(hand)
            # print(hand.label+'\n')
            # Creat histogram of each best hand
            prob_hist[hand.label] = prob_hist.get(hand.label, 0) + 1/total_hands*100
    # create dataframe of histogram
    table = pd.DataFrame.from_dict(prob_hist,orient='index', columns=['Best Hand Probability(%)'])
    print(table)
    print(f'\n Out of {total_hands} Total Hands')




コード例 #12
0
        self.suits = {}
        for card in self.cards:
            self.suits[card.suit] = self.suits.get(card.suit, 0) + 1

    def has_flush(self):
        """Returns True if the hand has a flush, False otherwise.
      
        Note that this works correctly for hands with more than 5 cards.
        """
        self.suit_hist()
        for val in self.suits.values():
            if val >= 5:
                return True
        return False


if __name__ == '__main__':
    # make a deck
    deck = Deck()
    deck.shuffle()

    # deal the cards and classify the hands
    for i in range(7):
        hand = PokerHand()
        deck.move_cards(hand, 7)
        hand.sort()
        print(hand)
        print(hand.has_flush())
        print('')