Hearthstone deck drawing sampler
import random | |
num_samples = 10 ** 6 | |
def make_deck(special_cards): | |
assert(isinstance(special_cards, list)) | |
assert(len(special_cards) <= 30) | |
thelist = special_cards | |
while len(special_cards) < 30: | |
thelist.append('*') | |
return thelist | |
def simulate(the_card, num_copies, copies_str, num_cards, turn_str, draw, mulligan, mulligan_str): | |
deck = make_deck([the_card] * num_copies) | |
count = 0 | |
for i in xrange(num_samples): | |
if the_card in random.sample(deck, num_cards): | |
count += 1 | |
continue | |
if mulligan: | |
# note: we can't draw the cards that were mulliganed the first time | |
deck_after_tossing = deck[:-num_cards] | |
# toss everything, sample again: | |
if the_card in random.sample(deck_after_tossing, num_cards): | |
count += 1 | |
continue | |
if draw: | |
drawn = random.sample(deck_after_tossing, 1)[0] | |
if the_card is drawn: | |
count += 1 | |
proba_pct = float(count) / num_samples * 100 | |
if draw: | |
print 'In decks with %d %-6s of %s, it was in %.2f%% of hands after turn 1 draw, with hard mulligan' % (num_copies, copies_str, the_card, proba_pct) | |
else: | |
print 'In decks with %d %-6s of %s, it was in %.2f%% of starting hands going %-6s %-6s mulligan' % (num_copies, copies_str, the_card, proba_pct, turn_str, mulligan_str) | |
def main(): | |
the_card = 'Undertaker' | |
print 'Sampling everything %d times' % num_samples | |
for mulligan in (False, True): | |
mulligan_str = 'before' | |
if mulligan is True: | |
mulligan_str = 'after' | |
for draw in (False, True): | |
# no point in simulating turn 1 if we don't mulligan | |
if draw and not mulligan: | |
continue | |
for num_copies in (1, 2): | |
copies_str = 'copy' | |
if num_copies != 1: | |
copies_str = 'copies' | |
for num_cards in (3, 4): | |
turn_str = 'first' | |
if num_cards is 4: | |
turn_str = 'second' | |
simulate(the_card, num_copies, copies_str, num_cards, turn_str, draw, mulligan, mulligan_str) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment