forked from Dreian/csweekmon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
96 lines (88 loc) · 3.6 KB
/
run.py
File metadata and controls
96 lines (88 loc) · 3.6 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
"""Entry point for the game."""
import argparse
import game_engine
import strategies
from utils import Printer
from csweekmon import Csweekmon
STRATEGIES = [
strategies.SimpleStrategy,
strategies.TankStrategy,
strategies.GlassCannonStrategy
]
NSTRATEGIES = len(STRATEGIES)
SCORES = dict()
WINS = dict()
DRAW = dict()
LOSS = dict()
def main():
"""Run tournament."""
# Validate strategies and make sure they have unique names
for strategy in STRATEGIES:
agent = Csweekmon(strategy, True)
name = agent.stats['Name']
if name in SCORES:
print('Name {} used in two strategies, please change this and rerun.'.format(name))
exit(0)
if not game_engine.verify(agent):
print("Strategy {} disqualified: failed game engine verification.".format(name))
SCORES[name] = -1
else:
print('Strategy {} is valid.'.format(name))
SCORES[name] = 0
WINS[name] = 0
DRAW[name] = 0
LOSS[name] = 0
# Run the tournament
battle_idx = 0
num_battles = NSTRATEGIES * (NSTRATEGIES - 1)
for i in range(NSTRATEGIES):
for j in range(NSTRATEGIES):
if i != j:
battle_idx += 1
csw1, csw2 = Csweekmon(STRATEGIES[i], True), Csweekmon(STRATEGIES[j], False)
print('###Battle {}/{}: {} vs {}'.format(battle_idx, num_battles,
csw1.name, csw2.name))
if SCORES[csw1.name] == -1 or SCORES[csw2.name] == -1:
print(' Battle skipped, at least one competitor was DQ!')
continue
outcome = game_engine.run_battle(csw1, csw2)
if outcome == 1:
SCORES[csw1.name] += 3
WINS[csw1.name] += 1
LOSS[csw2.name] += 1
print(' Winner: {}'.format(csw1.name))
elif outcome == 2:
SCORES[csw2.name] += 3
WINS[csw2.name] += 1
LOSS[csw1.name] += 1
print(' Winner: {}'.format(csw2.name))
else:
SCORES[csw1.name] += 1
SCORES[csw2.name] += 1
DRAW[csw1.name] += 1
DRAW[csw2.name] += 1
print(' It\'s a draw!')
# print scoreboard
print('SCOREBOARD:')
print('|-rank-|--------name--------|-pts-|-mpl-|--v--|--d--|--l--|')
print('-'*59)
matches_played = 2 * (NSTRATEGIES - 1)
sorted_scores = sorted(SCORES.items(), key=lambda kv: kv[1], reverse=True)
rank = 1
for name, pts in sorted_scores:
print('|{}|{}|{}|{}|{}|{}|{}|'.format(str(rank).center(6), name.center(20),
str(pts).center(5), str(matches_played).center(5),
str(WINS[name]).center(5), str(DRAW[name]).center(5),
str(LOSS[name]).center(5)))
rank += 1
print('-'*59)
if __name__ == "__main__":
PARSER = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
PARSER.add_argument('--no-verbose', action='store_true',
help='disable verbose output of the matches (skip to final scoreboard')
PARSER.add_argument('--delay', type=float, metavar='D', default=1.0,
help='number of seconds between ui ticks if verbose mode is on')
ARGS = PARSER.parse_args()
Printer.VERBOSE_OUTPUT = not ARGS.no_verbose
Printer.DELAY = ARGS.delay
main()