Skip to content

Commit 93f2561

Browse files
authored
Merge pull request #136 from don4get/master
Update manager to comply with new halite 3 arguments
2 parents 80edde8 + ec63c72 commit 93f2561

File tree

3 files changed

+17
-49
lines changed

3 files changed

+17
-49
lines changed

tools/manager/manager.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
# db_filename is now specified at command line, with the default set to "db.sqlite3"
3333
browser_binary = "firefox"
3434

35+
3536
def max_match_rounds(width, height):
3637
return 300 # FIXME check the actual final forumla
3738

3839

39-
4040
class Manager:
4141
def __init__(self, halite_binary, db_filename, players=None, rounds=-1, players_max=4):
4242
self.halite_binary = halite_binary
@@ -85,7 +85,6 @@ def pick_contestants(self, num):
8585
random.shuffle(contestants)
8686
return contestants
8787

88-
8988
def run_rounds(self, player_dist, map_dist):
9089
try:
9190
self.run_rounds_unix(player_dist, map_dist)
@@ -155,9 +154,6 @@ def show_results(self, offset, limit):
155154
def view_replay_id(self, id):
156155
filename = self.db.get_replay_filename(id)
157156
view_replay(filename)
158-
159-
160-
161157

162158

163159
def view_replay(filename):
@@ -398,6 +394,7 @@ def act(self):
398394
elif self.no_args:
399395
self.parser.print_help()
400396

397+
401398
cmd = Commandline()
402399
cmd.parse(sys.argv[1:])
403400
cmd.act()

tools/manager/match.py

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
record_dir = "replays"
1111

12+
1213
def update_skills(players, ranks):
1314
""" Update player skills based on ranks from a match """
1415
teams = [skills.Team({player.name: skills.GaussianRating(player.mu, player.sigma)}) for player in players]
1516
match = skills.Match(teams, ranks)
1617
calc = trueskill.FactorGraphTrueSkillCalculator()
1718
game_info = trueskill.TrueSkillGameInfo()
1819
updated = calc.new_ratings(match, game_info)
19-
print ("Updating ranks")
2020
for team in updated:
2121
player_name, skill_data = next(iter(team.items())) #in Halite, teams will always be a team of one player
2222
player = next(player for player in players if player.name == str(player_name)) #this suggests that players should be a dictionary instead of a list
@@ -25,6 +25,7 @@ def update_skills(players, ranks):
2525
player.update_skill()
2626
print("skill = %4f mu = %3f sigma = %3f name = %s" % (player.skill, player.mu, player.sigma, str(player_name)))
2727

28+
2829
class Match:
2930
def __init__(self, players, width, height, seed, time_limit, keep_replays, keep_logs):
3031
print("Seed = " + str(seed))
@@ -43,7 +44,6 @@ def __init__(self, players, width, height, seed, time_limit, keep_replays, keep_
4344
self.num_players = len(players)
4445
self.keep_replay = keep_replays
4546
self.keep_logs = keep_logs
46-
self.parameters = None
4747
self.logs = None
4848
self.map_generator = None
4949

@@ -56,63 +56,33 @@ def __repr__(self):
5656
return title1 + title2 + dims + results + replay
5757

5858
def get_command(self, halite_binary):
59-
dims = "-d " + str(self.map_width) + " " + str(self.map_height)
60-
quiet = "-q"
59+
if self.keep_replay is True:
60+
replays = "--replay-directory replays/"
61+
else:
62+
replays = "--no-replay"
63+
width = "--width 32"
64+
height = "--height 32"
6165
seed = "-s " + str(self.map_seed)
62-
result = [halite_binary, dims, quiet, seed]
66+
results = "--results-as-json"
67+
result = [halite_binary, replays, width, height, seed, results]
68+
if self.keep_logs is False:
69+
result.append("--no-logs")
70+
6371
return result + self.paths
6472

6573
def run_match(self, halite_binary):
6674
command = self.get_command(halite_binary)
6775
print("Command = " + str(command))
6876
p = Popen(command, stdin=None, stdout=PIPE, stderr=None)
6977
results, _ = p.communicate(None, self.total_time_limit)
78+
7079
self.results_string = results.decode('ascii')
7180
self.return_code = p.returncode
7281
self.parse_results_string()
7382
update_skills(self.players, copy.deepcopy(self.results))
74-
if self.keep_replay:
75-
print("Keeping replay\n")
76-
if not os.path.exists(record_dir):
77-
os.makedirs(record_dir)
78-
try:
79-
shutil.move(self.replay_file, record_dir)
80-
if self.replay_file.startswith('./'):
81-
self.replay_file = self.replay_file[2:]
82-
self.replay_file = os.path.join(record_dir, self.replay_file)
83-
except Exception as e:
84-
print(e)
85-
else:
86-
print("Deleting replay\n")
87-
os.remove(self.replay_file)
88-
89-
if self.keep_logs:
90-
print("Keeping logs\n")
91-
if not os.path.exists(record_dir):
92-
os.makedirs(record_dir)
93-
try:
94-
for key, filename in self.logs.items():
95-
shutil.move(filename, record_dir)
96-
self.logs[key] = os.path.join(record_dir, filename)
97-
except Exception as e:
98-
print(e)
99-
else:
100-
print("Deleting logs\n")
101-
for file in self.logs.values():
102-
os.remove(file)
103-
# self.fix_logs()
104-
105-
# def fix_logs(self):
106-
# print("Fixing logs")
107-
# for index in range(0, self.num_players):
108-
# if not self.logs[index]:
109-
# self.logs[index] = None
110-
# print(self.logs)
111-
11283

11384
def parse_results_string(self):
11485
data = json.loads(self.results_string)
115-
self.parameters = data['gameplay_parameters']
11686
self.logs = data['error_logs']
11787
self.map_height = data['map_height']
11888
self.map_width = data['map_width']

tools/manager/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
skills

0 commit comments

Comments
 (0)