Skip to content

Instantly share code, notes, and snippets.

@hpoggie
Created August 17, 2020 00:24
Show Gist options
  • Save hpoggie/2554a3def69d1b18db2c18377b1c85f2 to your computer and use it in GitHub Desktop.
Save hpoggie/2554a3def69d1b18db2c18377b1c85f2 to your computer and use it in GitHub Desktop.
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