Created
March 31, 2015 05:14
-
-
Save foxor/f38559c839704e756efb to your computer and use it in GitHub Desktop.
Figure out the hit-rate for a hearthstone combo
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
#!/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