forked from iteratedecks/fansiteSubmission
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulatorTyrantOptimizer.py
86 lines (66 loc) · 2.86 KB
/
simulatorTyrantOptimizer.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
#!/usr/bin/env python
import re
import subprocess
from fansiteSimulator import FansiteSimulator
class SimulatorTyrantOptimizer(FansiteSimulator):
name = "Tyrant Optimizer"
executable = "tyrant_optimize.exe"
results_regex = re.compile(r"win%: \S+ \((\d+) / (\d+)\)"
r"\s+(?:slay|stall)%: \S+ \((\d+) / \d+\)"
r"\s+loss%: \S+ \((\d+) / \d+\)"
r"(?:\s+(ard|achievement%): \S+ \((\d+) / \d+\))?")
results_keys = ["wins", "total", "draws", "losses", "ard"]
def loadVersion(self):
commandArgs = [self.executable, "-version"]
result = subprocess.check_output(commandArgs)
return result.split()[2]
def processResults(self, results):
match = self.results_regex.search(results)
if not match:
print("ERROR: Cannot find results from output {{{\n", results, "}}}")
return None
wins, total, slay_stalls, losses, points_type, points = match.groups()
results = dict()
if points_type == "achievement%":
results["wins"] = points
else:
results["wins"] = wins
results["total"] = total
if points_type == "ard":
results["draws"] = 0
else:
results["draws"] = slay_stalls
results["losses"] = losses
if points_type == "ard":
results["ard"] = float(points) / int(total)
return results
def addAchievement(self, commandArgs, achievementId, missionId):
commandArgs.append("Mission #%s" % missionId)
commandArgs.extend(["-A", str(achievementId)])
def addAttackingDeck(self, commandArgs, attackingDeck, attackingDeckCards):
commandArgs.append(attackingDeck)
def addBattlegroundId(self, commandArgs, battlegroundId):
commandArgs.extend(["-e", str(battlegroundId)])
def addCustom(self, commandArgs, custom):
commandArgs.append(custom)
def addDefendingExactOrdered(self, commandArgs):
commandArgs.append("defender:exact-ordered")
def addDefendingOrdered(self, commandArgs):
commandArgs.append("defender:ordered")
def addDelayed(self, commandArgs):
commandArgs.append("tournament")
def addExactOrdered(self, commandArgs):
commandArgs.append("exact-ordered")
def addExtraArgs(self, commandArgs, args):
commandArgs.extend(["-t", str(getattr(args, "numThreads", 1))])
commandArgs.extend(["sim", str(args.numSims)])
def addMission(self, commandArgs, missionId):
commandArgs.append("Mission #%s" % missionId)
def addOrdered(self, commandArgs):
commandArgs.append("ordered")
def addQuest(self, commandArgs, questId):
commandArgs.append("Quest #%s" % questId)
def addRaid(self, commandArgs, raidId):
commandArgs.append("Raid #%s" % raidId)
def addSurge(self, commandArgs):
commandArgs.append("-s")