Last active
August 29, 2015 14:10
-
-
Save dreynaud/f3119bf52ab407ca6594 to your computer and use it in GitHub Desktop.
Hearthstone deck drawing sampler
This file contains hidden or 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 | |
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