Created
August 17, 2020 00:24
-
-
Save hpoggie/2554a3def69d1b18db2c18377b1c85f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def sim_game(): | |
n_cards = 48 # Total number of cards remaining in deck | |
n_squires = 4 # Number of squires in deck | |
hand_size = 0 # Total cards in hand | |
def draw_card(): | |
nonlocal n_cards, n_squires, hand_size | |
# Draw card without replacement | |
# randint goes from 0 to n_cards - 1 | |
if random.randint(0, n_cards) < n_squires: | |
n_squires -= 1 | |
if n_squires == 0: | |
return True | |
n_cards -= 1 | |
hand_size += 1 | |
return False | |
# Opening hand. See 5 completely new cards. | |
for i in range(5): | |
if draw_card(): | |
return True | |
for turn in range(4): | |
# Draw a completely new card | |
if draw_card(): | |
return True | |
# Do Magician | |
# How many cards should we mulligan? | |
squires_in_hand = 4 - n_squires | |
to_mul = hand_size - squires_in_hand | |
n_cards += to_mul | |
hand_size -= to_mul | |
for i in range(to_mul): | |
if draw_card(): | |
return True | |
return False | |
def sim(): | |
tries = 100000 | |
successes = 0 | |
for i in range(tries): | |
if sim_game(): | |
successes += 1 | |
return successes / tries | |
if __name__ == "__main__": | |
print(sim()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment