-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvantage.py
More file actions
63 lines (39 loc) · 1.17 KB
/
advantage.py
File metadata and controls
63 lines (39 loc) · 1.17 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# vim: set expandtab ts=4 sw=4 filetype=python fileencoding=utf8:
import collections
import pprint
import random
def _1d20():
return random.choice(range(1, 21))
def roll_with_advantage():
return max([_1d20(), _1d20()])
if __name__ == "__main__":
score = collections.defaultdict(int)
nat20s = collections.defaultdict(int)
for _ in range(1000*1000):
a = roll_with_advantage()
if a == 20:
nat20s["advantage"] += 1
b = _1d20()
if b == 20:
nat20s["1d20"] += 1
c = _1d20() + 1
if c == 21:
nat20s["1d20+1"] += 1
d = _1d20() + 3
if d == 23:
nat20s["1d20+3"] += 1
e = _1d20() + 5
if e == 25:
nat20s["1d20+5"] += 1
if max([a, b, c, d, e]) == a:
score["advantage"] += 1
if max([a, b, c, d, e]) == b:
score["1d20"] += 1
if max([a, b, c, d, e]) == c:
score["1d20+1"] += 1
if max([a, b, c, d, e]) == d:
score["1d20+3"] += 1
if max([a, b, c, d, e]) == e:
score["1d20+5"] += 1
pprint.pprint(nat20s)
pprint.pprint(score)