-
Notifications
You must be signed in to change notification settings - Fork 0
/
TheMathAge_stat.py
198 lines (155 loc) · 5.7 KB
/
TheMathAge_stat.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
'''
Created on 27. feb. 2017
@author: tsy
License: CC-BY
'''
from random import randint
import numpy as np
if __name__ == '__main__':
pass
def roll(dice):
res = 0
for n in range(dice):
res =+ randint(1,6)
return res
def charge(M=None,distance = None,swiftStride=False):
assert M is not None
assert distance is not None
res = list()
chargePassed = False
res.append(roll(1))
res.append(roll(1))
if swiftStride:
res.append(roll(1))
chargeRange= sum(res) - min(res)
else:
chargeRange=sum(res)
if chargeRange >= distance:
chargePassed = True
return chargePassed
def LdTest(Ld=None,reRoll=False,coldBlood=False):
assert Ld is not None
def __test__(Ld,reRoll,coldBlood):
passTest = False
res = list()
res.append(roll(1))
res.append(roll(1))
if coldBlood:
res.append(roll(1))
score = sum(res) - max(res)
else:
score = sum(res)
if score<=Ld:
passTest = True
return passTest
passTest = __test__(Ld,reRoll,coldBlood)
if passTest is False and reRoll is True:
passTest = __test__(Ld,reRoll,coldBlood)
return passTest
def cast(dice=None,castValue=None):
assert type(dice) is not None
assert castValue is not None
assert dice < 6
assert castValue <20
spellCast = True
res = list()
#cast dice
for n in range(dice):
res.append(roll(1))
#check for OP and roll another dice if OP
res.sort()
if dice>1:
if res[-1] is 6 and res[-2] is 6:
res.append(roll(1))
#summarize castScore
castScore = sum(res)
#check against castValue
if castScore<castValue:
spellCast = False
return spellCast
def printTables():
N = 250000 # number of seeds for each simulation
printCharge = True
printLd = True
printMagic = True
if printCharge:
'''charge range'''
#distances to check
chargeRes = list()
QSres = list()
for m in range(3,13):
#runs/seeds
res = list()
append = res.append
for n in range(N):
append(charge(M=0,distance = m,swiftStride=False))
chargeRes.append(np.mean(res)*100)
res = list()
append = res.append
for n in range(N):
append(charge(M=0,distance = m,swiftStride=True))
QSres.append(np.mean(res)*100)
if printLd:
'''Leadership tests'''
resNormal= list()
resColdBlood=list()
resReRoll = list()
resReRollCB = list()
for ld in range(2,11):
l1=list()
l2 = list()
l3 = list()
l4 = list()
for n in range(N):
l1.append(LdTest(Ld=ld,reRoll=False,coldBlood=False))
l2.append(LdTest(Ld=ld,reRoll=False,coldBlood=True))
l3.append(LdTest(Ld=ld,reRoll=True,coldBlood=False))
l4.append(LdTest(Ld=ld,reRoll=True,coldBlood=True))
resNormal.append(np.mean(l1)*100)
resColdBlood.append(np.mean(l2)*100)
resReRoll.append(np.mean(l3)*100)
resReRollCB.append(np.mean(l4)*100)
if printMagic:
'''casting tests'''
res1d6 = list()
res2d6 = list()
res3d6 = list()
res4d6 = list()
res5d6 = list()
for castValue in range(3,20):
l1=list()
l2 = list()
l3 = list()
l4 = list()
l5 = list()
for n in range(N):
l1.append(cast(dice=1,castValue=castValue))
l2.append(cast(dice=2,castValue=castValue))
l3.append(cast(dice=3,castValue=castValue))
l4.append(cast(dice=4,castValue=castValue))
l5.append(cast(dice=5,castValue=castValue))
res1d6.append(np.mean(l1)*100)
res2d6.append(np.mean(l2)*100)
res3d6.append(np.mean(l3)*100)
res4d6.append(np.mean(l4)*100)
res5d6.append(np.mean(l5)*100)
if printCharge:
print(' Charges:')
print('Charge: %s' % ', '.join('\t{:.1f}'.format(e) for e in chargeRes))
print('Swiftstride: %s' % ', '.join('\t{:.1f}'.format(e) for e in QSres) )
print('----------------------------------------------------------------------------' )
if printLd:
print(' Leadership Tests:')
print('2d6: %s' % ', '.join('\t{:.1f}'.format(e) for e in resNormal) )
print('2d6 + reroll: %s' % ', '.join('\t{:.1f}'.format(e) for e in resReRoll) )
print('d26 + Cold Blood: %s' % ', '.join('\t{:.1f}'.format(e) for e in resColdBlood))
print('d26 + Cold Blood + reroll: %s' % ', '.join('\t{:.1f}'.format(e) for e in resReRollCB) )
print('----------------------------------------------------------------------------' )
if printMagic:
print(' Chance to Pass and dispel:')
print('1d6:%s' % ', '.join('\t{:.1f}'.format(e) for e in res1d6))
print('2d6:%s' % ', '.join('\t{:.1f}'.format(e) for e in res2d6))
print('3d6:%s' % ', '.join('\t{:.1f}'.format(e) for e in res3d6))
print('4d6:%s' % ', '.join('\t{:.1f}'.format(e) for e in res4d6))
print('5d6:%s' % ', '.join('\t{:.1f}'.format(e) for e in res5d6))
printTables()