コード例 #1
0
    def test_get_diminishing_straights_probabibilty():
        """
        Given a custom deck, calculate the probability of the deck having a 3-card straight.
        Then remove the lowest cards, one by one, and calculate the probabilities again, etc.
        """

        straight_length = 3
        max_iterations = 50000

        straight_count_frequencies = dict()

        for i in range(3, 13):
            straight_count_frequencies[i] = 0

        for i in range(max_iterations):

            deck = Deck(custom_suits={"𓆏": "GREEN", "𓃰": "GREY"})

            deck.double_cards()
            deck.shuffle()
            deck.remove_cards(lambda_statement=lambda x: x.rank != "A",
                              index=13)

            hand = deck.get_sample_hand(12)

            while len(hand.cards) >= straight_length:
                if hand.evaluator.has_straight(straight_length):
                    straight_count_frequencies[len(hand.cards)] += 1

                hand.remove_lowest_ranked_card()

        for i in sorted(straight_count_frequencies.keys()):
            print(
                "The probability of a hand containing a {}-card straight given its {} highest cards is around {} %."
                .format(straight_length, i,
                        straight_count_frequencies[i] / max_iterations * 100))