def test_get_foak_probability(): foak_count = 0 iterations = 100000 for i in range(0, iterations): deck = Deck(custom_suits={"𓆏": "GREEN", "𓃰": "GREY"}) deck.double_cards() deck.shuffle() deck.remove_cards(lambda_statement=lambda x: x.rank != "A", index=13) if deck.evaluator.has_four_of_a_kind(): foak_count += 1 print( "The probability of having a four-of-a-kind given this custom deck is around {} %." .format(foak_count / iterations * 100))
def test_get_straights_probability(): for i in range(3, 9): straight_count = 0 straight_length = i iterations = 50000 for j in range(0, iterations): deck = Deck(custom_suits={"𓆏": "GREEN", "𓃰": "GREY"}) deck.double_cards() deck.shuffle() deck.remove_cards(lambda_statement=lambda x: x.rank != "A", index=13) if deck.evaluator.has_straight(straight_length): straight_count += 1 print( "The probability of this deck containing a {}-card straight is around {} %." .format(straight_length, straight_count / iterations * 100))
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))
def test_remove_cards(self): deck = Deck(custom_suits={"𓆏": "GREEN", "𓃰": "GREY"}) deck.double_cards() deck.remove_cards(lambda x: x.rank != "A") self.assertTrue(len(deck.cards) == 48)