Skip to content

Instantly share code, notes, and snippets.

@foxor
Created March 31, 2015 05:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxor/f38559c839704e756efb to your computer and use it in GitHub Desktop.
Save foxor/f38559c839704e756efb to your computer and use it in GitHub Desktop.
Figure out the hit-rate for a hearthstone combo
#!/usr/bin/env python
import random
_memoize = []
def fac(x):
if x < 0:
return 1
if len(_memoize) <= x:
_memoize.append(1 if x == 0 else x * fac(x - 1))
return _memoize[x] * 1.0
HS_DECK = 30
TARGET_TURN = 3
COMBO_PARTS = [2, 4] # 2 Darkwing Technicians and 5 Dragons
TRIALS = 10000
def trial(part_range_list):
deck = [min(y for y in part_range_list if y > x) if part_range_list[-1] > x else -1 for x in xrange(HS_DECK)]
deck.sort(key = lambda x: random.random())
mulligan_cards = 4 if random.random() > 0.5 else 3
keepers = len(set(x for x in deck[:mulligan_cards] if x != -1))
seen = mulligan_cards - keepers + TARGET_TURN
return len(set(x for x in deck[:seen] if x != -1)) == len(COMBO_PARTS)
def build_part_range_list():
copy = COMBO_PARTS[:]
for x in xrange(1, len(copy)):
copy[x] = copy[x] + copy[x - 1]
return copy
def main():
part_range_list = build_part_range_list()
successes = sum(1 for x in xrange(TRIALS) if trial(part_range_list))
print "Ran %d tests with %.2f%% success rate." % (TRIALS, (100.0 * successes) / TRIALS)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment