Skip to content

Commit 0e6ef7c

Browse files
committed
Update Core War tests
1 parent 12a4db6 commit 0e6ef7c

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

tests/arenas/test_corewar.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,25 @@ def arena(self, tmp_log_dir, minimal_config):
106106

107107
def _create_sim_log(self, round_dir, scores: list[tuple[str, str, int]]):
108108
"""
109-
Create a simulation log file.
109+
Create simulation log files (one per agent).
110110
111111
Args:
112+
round_dir: Directory to create log files in
112113
scores: List of (warrior_name, author, score) tuples
113114
"""
114-
log_file = round_dir / COREWAR_LOG
115-
lines = ["pMARS 0.8.6\n", "Starting simulation...\n"]
116-
for warrior_name, author, score in scores:
117-
lines.append(f"{warrior_name} by {author} scores {score}\n")
118-
log_file.write_text("".join(lines))
115+
# Create one sim_{idx}.log file per agent to match new logging structure
116+
for idx in range(len(scores)):
117+
log_file = round_dir / COREWAR_LOG.format(idx=idx)
118+
# Rotate player order to match what _run_single_simulation does
119+
rotated_scores = scores[idx:] + scores[:idx]
120+
121+
lines = []
122+
for warrior_name, author, score in rotated_scores:
123+
lines.append(f"{warrior_name} by {author} scores {score}\n")
124+
# Results line: wins for each player, then ties (always 0)
125+
wins = " ".join([str(score) for _, _, score in rotated_scores] + ["0"])
126+
lines.append(f"Results: {wins}\n")
127+
log_file.write_text("".join(lines))
119128

120129
def test_parse_results_player1_wins(self, arena, tmp_log_dir):
121130
"""Test parsing results when player 1 has higher score."""
@@ -136,8 +145,8 @@ def test_parse_results_player1_wins(self, arena, tmp_log_dir):
136145
arena.get_results(agents, round_num=1, stats=stats)
137146

138147
assert stats.winner == "Alice"
139-
assert stats.scores["Alice"] == 150
140-
assert stats.scores["Bob"] == 100
148+
assert stats.scores["Alice"] == 300 # 150 per sim * 2 sims
149+
assert stats.scores["Bob"] == 200 # 100 per sim * 2 sims
141150

142151
def test_parse_results_player2_wins(self, arena, tmp_log_dir):
143152
"""Test parsing results when player 2 has higher score."""
@@ -158,8 +167,8 @@ def test_parse_results_player2_wins(self, arena, tmp_log_dir):
158167
arena.get_results(agents, round_num=1, stats=stats)
159168

160169
assert stats.winner == "Bob"
161-
assert stats.scores["Alice"] == 80
162-
assert stats.scores["Bob"] == 200
170+
assert stats.scores["Alice"] == 160 # 80 per sim * 2 sims
171+
assert stats.scores["Bob"] == 400 # 200 per sim * 2 sims
163172

164173
def test_parse_results_tie(self, arena, tmp_log_dir):
165174
"""Test parsing results when scores are equal."""
@@ -179,9 +188,9 @@ def test_parse_results_tie(self, arena, tmp_log_dir):
179188

180189
arena.get_results(agents, round_num=1, stats=stats)
181190

182-
# With equal scores, first player with max wins (implementation detail)
183-
assert stats.scores["Alice"] == 150
184-
assert stats.scores["Bob"] == 150
191+
# With equal wins, result is determined by score tiebreaker
192+
assert stats.scores["Alice"] == 300 # 150 per sim * 2 sims
193+
assert stats.scores["Bob"] == 300 # 150 per sim * 2 sims
185194

186195

187196
class TestCoreWarConfig:

0 commit comments

Comments
 (0)