Created
March 7, 2015 08:47
-
-
Save mcpower/1a54bf15414b2d9e5a4e to your computer and use it in GitHub Desktop.
Grim Patron + Bouncing Blade
This file contains 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
from __future__ import division, print_function # Python 3 backwards compatible (and I'm lazy/hacky) | |
outcomes = 0 | |
# zip mult sum | |
# returns [a[0] * amult + b[0] * bmult, a[1] * amult + b[1] * bmult, ...] | |
def zms(a, b, amult=1, bmult=1): | |
return list(map(lambda x, y: x * amult + y * bmult, a, b)) | |
# cache decorator | |
def cache(f): | |
c={} | |
return lambda*x:c.setdefault(x,x in c or f(*x)) | |
# returns (possibilities of 0 minions, 1, 2, ..., 6) | |
@cache | |
def minion_count(three, two, one): | |
global outcomes | |
outcomes += 1 | |
num_minions = three + two + one | |
out = [0, 0, 0, 0, 0, 0, 0] | |
if three: | |
out = zms(minion_count(three - (num_minions == 7), two + 1, one), out, three / num_minions) # abusing boolean logic for Don't Repeat Yourself | |
if two: | |
out = zms(minion_count(three + (num_minions != 7), two - 1, one + 1), out, two / num_minions) | |
if one: | |
out[num_minions - 1] += one / num_minions # subtract one for the dead one | |
return tuple(out) | |
# speaking of Don't Repeat Yourself, 90% of this code is repeated from above | |
# returns attack/health | |
@cache | |
def stats(three, two, one): | |
num_minions = three + two + one | |
out = [0, 0] | |
if three: | |
out = zms(stats(three - (num_minions == 7), two + 1, one), out, three / num_minions) | |
if two: | |
out = zms(stats(three + (num_minions != 7), two - 1, one + 1), out, two / num_minions) | |
if one: | |
out = zms([3 * (num_minions - 1), 3 * three + 2 * two + one - 1], out, one / num_minions) | |
return tuple(out) | |
minion_count_results = minion_count(1,0,0) | |
stats_results = stats(1,0,0) | |
print("evaluated", outcomes, "outcomes") | |
print(*["%d minions %.2f%% chance" % (i, odds*100) for i, odds in enumerate(minion_count_results)], sep="\n") | |
print("average stats:", "/".join("%.4f" % x for x in stats_results)) |
This file contains 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
evaluated 36 outcomes | |
0 minions 0.00% chance | |
1 minions 0.00% chance | |
2 minions 16.67% chance | |
3 minions 16.67% chance | |
4 minions 15.83% chance | |
5 minions 13.06% chance | |
6 minions 37.78% chance | |
average stats: 13.1583/10.0951 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment