Created
January 13, 2018 15:00
-
-
Save dreispt/2ee7dc0fee52f5defc957d909073488e to your computer and use it in GitHub Desktop.
Dice Stats created by dreispt - https://repl.it/@dreispt/Dice-Stats
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
import itertools | |
def freqs_calc(calc_func, dice): | |
combs = itertools.product(*tuple(dice)) | |
res = dict() | |
for comb in combs: | |
#import pdb; pdb.set_trace() | |
x = calc_func(*comb) | |
res.setdefault(x, 0) | |
res[x] = res[x] + 1 | |
return res | |
def freqs_print(res): | |
n = sum(res[x] for x in res) | |
a = 0 | |
print("x\t" "n\t" "%\t" "a\t" "<=%\t" ">=%\t") | |
print("=====\t" * 6) | |
res_list = list(res.items()) | |
res_list.sort() | |
for x, y in res_list: | |
a0 = a | |
a = a + y | |
print( | |
x, '\t', | |
y, '\t', | |
round(y / n * 100, 2), '\t', | |
a, '\t', | |
round(a / n * 100, 2), '\t', | |
round(100 - a0 / n * 100, 2)) | |
def calc_3d6(d1, d2, d3): | |
return d1 + d2 + d3 | |
def calc_3d6_10(d1, d2, d3): | |
return sum([d1//2-2, d2//2-2, d3//2-2]) | |
def calc_3d6med(d1, d2, d3): | |
dp = min(d1, d2) | |
dn = d3 | |
if dp < dn: | |
return dp | |
elif dn < dp: | |
return -dn | |
else: | |
return 0 | |
def calc_3d6fudge(d1, d2, d3): | |
if d1 == d2 and d2 == d3: | |
res = {0: 1, 1: 1, 2: 1, 3: 4.5, 4: 4.5, 5: 12, 6: 12}.get(d1) | |
else: | |
res = d1 + d2 + d3 - max(d1, d2, d3) | |
#print(d1, d2, d3, res) | |
return res | |
def calc_1dp1dn(dp, dn): | |
if dp < dn: | |
return dp | |
elif dp > dn: | |
return -dn | |
else: | |
return 0 | |
def calc_2dp2dn(dp1, dp2, dn1, dn2): | |
dp = min(dp1, dp2) | |
dn = min(dn1, dn2) | |
if dp < dn: | |
return dp | |
elif dp > dn: | |
return -dn | |
else: | |
return 0 | |
def calc_2d6_d6(d1, d2, d3): | |
res = d1 + d2 | |
if d1 == d2 and d1 in (5, 6): | |
res += d3 | |
return res | |
d6 = list(range(1, 7)) | |
print("== 2d6 ==") | |
freqs_print(freqs_calc(lambda *x: sum(x), [d6, d6])) | |
print("== 4dF ==") | |
df = [-1, -1, 0, 0, 1, 1] | |
freqs_print(freqs_calc(lambda *x: sum(x), 4 * [df])) | |
print("== 3d6 ==") | |
freqs_print(freqs_calc(lambda *x: sum(x), [d6] * 3)) | |
print("== 1dp1dn ==") | |
freqs_print(freqs_calc(calc_1dp1dn, [d6, d6])) | |
print("== 2dp2dn ==") | |
freqs_print(freqs_calc(calc_2dp2dn, [d6] * 4)) | |
print("== 3d05 ==") | |
d05 = [-2, -1, -1, 1 ,1 ,2] #[x-2 for x in list(range(1,7))] | |
freqs_print(freqs_calc(lambda *x: sum(x), [d05] * 3 )) | |
print("== 3d6fudge ==") | |
#d6 = [0,1,2,3,4,5]#[x-1 for x in list(range(1,7))] | |
freqs_print(freqs_calc(calc_3d6fudge, [d6] * 3 )) | |
print("== 2d6 + d6 ==") | |
freqs_print(freqs_calc(calc_2d6_d6, [d6] * 3 )) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment