-
Notifications
You must be signed in to change notification settings - Fork 0
/
dice_ave.py
executable file
·41 lines (29 loc) · 1.03 KB
/
dice_ave.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
"""dice_ave.py
compute brute-force average outcome of 3 atypical, but useful dice rolls
TODO: generalize, take command line inputs
"""
from __future__ import (print_function, division)
import numpy as np
# roll 4d6, keep best 3
rolls = np.array([ [w+1, x+1, y+1, z+1]
for w in range(6)
for x in range(6)
for y in range(6)
for z in range(6) ])
outcome = np.sum(rolls, axis=1) - np.min(rolls, axis=1)
ave_4d6 = np.mean(outcome)
print("4d6, keep 3 ave: {0}".format(ave_4d6))
# roll 2d20, keep best or worst 1
rolls = np.array([ [x+1, y+1]
for x in range(20)
for y in range(20) ])
adv = np.max(rolls, axis=1)
dis = np.min(rolls, axis=1)
ave_adv = np.mean(adv)
ave_dis = np.mean(dis)
ave_d20 = 10.5
adv = ave_adv - ave_d20
dis = ave_dis - ave_d20
print("d20 with advantage ave: {0}, i.e. {1:+0.3f}".format(ave_adv, adv))
print("d20 with disadvantage ave: {0}, i.e. {1:+0.3f}".format(ave_dis, dis))