-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
153 lines (127 loc) · 5.71 KB
/
main.py
File metadata and controls
153 lines (127 loc) · 5.71 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
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
from __future__ import annotations
from data.healers import PaladinHealer, DruidHealer
from simulator.mechanics import Fight
import data.buffs as b
import data.talents as ta
import simulator.units as units
import matplotlib.pyplot as plt
import multiprocessing as mp
import statistics as stat
import time
def run(fight: Fight):
fight.initialize()
fight.run()
return fight.statistics()
# results = list()
# def append_result(r):
# results.append(r)
def main():
'''
Tank: sta, agi, str, def, ddg, par, blo, b_v, armor, hit, exp, spd, talents, buffs
'''
pumpkinpie = units.PaladinTank(stamina=1345, agility=133, strength=0, defense_rating=418, dodge_rating=331,
parry_rating=30, block_rating=62, block_value=318, armor=30400, hit_rating=48,
expertise_rating=0, weapon_speed=1.8,
talents=(ta.CombatExpertise(5), ta.SacredDuty(2), ta.Deflection(5),
ta.RighteousFury(3), ta.PaladinShieldSpecialization(3),
ta.Anticipation(5), ta.Toughness(5)),
buffs=(b.iFortitude, b.iMotW, b.BoK, b.iCommandingShout, b.DevotionAura,
b.FlaskOfFortification, b.StaminaFood, b.ScrollOfProtection,
b.SunwellRadiance, b.InsectSwarm))
print(pumpkinpie)
'''
Boss: boss, level, dmg min - max, spd, school, abilities [11521, 22721]
'''
kalecgos = units.Boss('Kalecgos', 73, [24000, 26000], 2.0, 'physical')
'''
Boss: boss, level, dmg min - max, spd, school, abilities [11521, 22721]
'''
boss2 = units.Boss('Fathom-Guard Tidalvess', 73, [11099, 13992], 1.5, 'physical')
'''
Healer: bh, haste, crit
'''
eydel = PaladinHealer('Eydel', 2500, 0, 400)
epiphron = DruidHealer('Epiphron', 2200, 191, 242)
mawka = DruidHealer('Mawka', 2200, 191, 242)
R = 10000
print(f'Running {R} runs')
start = time.time()
# r = 0
# results = list()
# while r < R:
# f = Fight(units.Boss('Sathrovarr', 73, [24000, 26000], 2, 'physical'),
# pumpkinpie,
# [PaladinHealer('Eydel', 2500, 0, 400),
# DruidHealer('Epiphron', 2200, 191, 242)],
# duration=480)
# result = run(f)
# # print(result)
# results.append(result)
# r += 1
with mp.Pool(mp.cpu_count()) as pool:
results = pool.map(run, [Fight(units.Boss('Sathrovarr', 73, [24000, 26000], 2.0, 'physical'),
pumpkinpie,
[PaladinHealer('Eydel', 2500, 0, 400),
DruidHealer('Epiphron', 2200, 191, 242)],
duration=480) for i in range(R)])
print('Elapsed time {}s'.format(time.time() - start))
deaths = []
missed, dodged, parried, blocked, crushed, hit, totals, critical_events = ([] for i in range(8))
for i, result in enumerate(results):
if result[0].get_tank_hp().get_hp() <= 0:
deaths.append(i)
misses, dodges, parries, blocks, crushes, hits = result[0].get_stats()
total = misses + dodges + parries + blocks + crushes + hits
totals.append(total)
missed.append(misses/total*100)
dodged.append(dodges/total*100)
parried.append(parries/total*100)
blocked.append(blocks/total*100)
crushed.append(crushes/total*100)
hit.append(hits/total*100)
critical_events.append(result[0].get_critical_events())
print('missed mean: {} variance: {}'.format(stat.mean(missed), stat.stdev(missed)))
print('dodged mean: {} variance: {}'.format(stat.mean(dodged), stat.stdev(dodged)))
print('parried mean: {} variance: {}'.format(stat.mean(parried), stat.stdev(parried)))
print('blocked mean: {} variance: {}'.format(stat.mean(blocked), stat.stdev(blocked)))
print('crushed mean: {} variance: {}'.format(stat.mean(crushed), stat.stdev(crushed)))
print('hit mean: {} variance: {}'.format(stat.mean(hit), stat.stdev(hit)))
print('critical_events mean: {} variance: {}'.format(stat.mean(critical_events), stat.stdev(critical_events)))
print('{:.2f}% survival chance (survived {} out of {} tries)!'.format((R - len(deaths))/R * 100, R - len(deaths), R))
# t = [hp[0] for hp in results[0][0].get_tank_hp().get_fight()]
# hp = [hp[1] for hp in results[0][0].get_tank_hp().get_fight()]
# plt.plot(t, hp)
# plt.show()
with open('history.log', 'w') as f:
if not deaths:
for line in results[0][1]:
f.write(repr(line) + '\n')
graph(results[0][0].get_tank_hp())
print('First simulation written to history.log')
else:
for death in deaths:
try:
death_recount = results[death][1][-40:]
except IndexError:
death_recount = results[death][1]
for line in death_recount:
f.write(repr(line) + '\n')
print('All death recounts written to history.log')
# if deaths:
# time = [hp[0] for hp in results[deaths[0]][8].hp]
# hp = [hp[1] for hp in results[deaths[0]][8].hp]
# plt.plot(time, hp)
# plt.show()
# hist = results[0][0].get_tank_hp()
# t = [p[0] for p in hist._hp]
# hp = [p[1] for p in hist._hp]
# plt.plot(t, hp)
# plt.show()
def graph(tank_hp):
fight = tank_hp.get_fight()
time = [f[0] for f in fight]
hp = [f[1] for f in fight]
plt.plot(time, hp)
plt.show()
if __name__ == '__main__':
main()