-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.py
123 lines (97 loc) · 2.76 KB
/
tests.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
from pathlib import Path
from classes import *
from serializer import Serializer
from viz import histogram1, RollDefDashboard
from matplotlib import pyplot as plt
adv = RollDef(
2 * D(20),
Sum(Highest(1)),
name='advantage',
desc='''roll of a d20 with advantage'''
)
disadv = RollDef(
2 * D(20),
Sum(Lowest(1)),
name='disadvantage',
desc='''roll of a d20 with disadvantage'''
)
atts1 = RollDef(
RollDef(
4 * RollDef(
D(6),
ReRoll(EqualTo(1))),
Sum(Highest(3),)),
ReRoll(LessThan(14)),
name="very generous 4d6",
desc=
'''Generous method of rolling stats for dnd characters.
Roll 4 D6's and take the highest 3 as the sum. You may reroll 1's,
but only once. If you are unhappy with a stat, you may repeat the
process once.''')
atts2 = RollDef(
4 * RollDef(
D(6),
ReRoll(EqualTo(1))),
Sum(Highest(3),),
name="generous 4d6",
desc=
'''Generous method of rolling stats for dnd characters.
Roll 4 D6's and take the highest 3 as the sum. You may reroll 1's,
but only once.''')
atts3 = RollDef(
4 * D(6),
Sum(Highest(3)),
name="4D6, 3 highest, summed",
desc=
'''Simplest method of rolling stats for dnd characters.
Roll 4 D6's and take the sum of the best 3.''')
atts4 = RollDef(
3 * D(6),
Sum(),
name="4D6, 3 highest, summed",
desc=
'''Simplest method of rolling stats for dnd characters.
Roll 4 D6's and take the sum of the best 3.''')
inverse_1 = RollDef(
D([-1, 1]),
Sum(),
name="Inverter",
desc='''Either -1 or 1 produces pass/fail type scenarios''')
def test_serializer():
s = Serializer()
mypath = Path('Dnd_attribute_roll1.json')
mypath2 = Path('Dnd_attribute_roll2.json')
mypath3 = Path('Dnd_attribute_roll3.json')
my_rolldef = atts1 # use example rolldef
# do the first histogram
histogram1(my_rolldef(1e6))
s.dump(my_rolldef, mypath)
my_rolldef2 = s.load(mypath)
s.dump(my_rolldef2, mypath2)
my_rolldef3 = s.load(mypath2)
s.dump(my_rolldef3, mypath3)
# second histogram
histogram1(my_rolldef3(1e6))
def viz_reroll_strat():
rolldefs = [
RollDef(
RollDef(
4 * RollDef(
D(6),
ReRoll(EqualTo(1))),
Sum(Highest(3),)),
ReRoll(LessThan(i)),
name=f"RR LT {i}")
for i in range(9, 17, 1)
]
s = Serializer()
path = Path("jsonlib/reroll_strat.json")
#db = RollDefDashboard.from_rolldefs(rolldefs, n=1e4)
#s.dump(db, path)
db = s.load(path)
db.add_accuracy(8e6)
s.dump(db, path)
db.show()
if __name__ == "__main__":
from datetime import datetime
viz_reroll_strat()