Skip to content

Commit e9aa68e

Browse files
committed
Logging changes
1 parent a3a4977 commit e9aa68e

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

scripts/run_ladder.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,6 @@
1111
from codeclash.utils.yaml_utils import resolve_includes
1212

1313

14-
def win_condition(tournament_dir: Path, name: str) -> bool:
15-
"""Player must have won majority of rounds and the last round to continue ladder"""
16-
metadata_path = tournament_dir / "metadata.json"
17-
with open(metadata_path) as f:
18-
metadata = yaml.safe_load(f)
19-
round_winners = [r["winner"] for r in metadata["round_stats"].values()]
20-
21-
player_wins = sum(1 for w in round_winners if w == name)
22-
player_won_last = round_winners[-1] == name
23-
return player_wins > len(round_winners) // 2 and player_won_last
24-
25-
2614
def main(
2715
config_path: Path,
2816
*,
@@ -48,6 +36,7 @@ def main(
4836
parent_dir = LOCAL_LOG_DIR / getpass.getuser() / ladder_folder
4937

5038
for idx, opponent in enumerate(ladder):
39+
opponent_rank = len(ladder) - idx
5140
opponent["name"] = opponent["branch_init"].replace("human/", "").replace("/", "_")
5241
if "branch_init" in player and idx > 0:
5342
# After first opponent, remove branch_init so that player continues from previous tournament's codebase
@@ -75,13 +64,30 @@ def main(
7564
)
7665
tournament.run()
7766

78-
# If player lost tournament, ladder challenge ends
79-
if not win_condition(tournament_dir, player["name"]):
67+
# Get results
68+
metadata_path = tournament_dir / "metadata.json"
69+
with open(metadata_path) as f:
70+
metadata = yaml.safe_load(f)
71+
round_winners = [r["winner"] for r in metadata["round_stats"].values()]
72+
73+
# Player must have won majority of rounds and the last round to continue ladder
74+
player_wins = sum(1 for w in round_winners if w == player["name"])
75+
player_won_last = round_winners[-1] == player["name"]
76+
77+
if not player_wins > len(round_winners) // 2 or not player_won_last:
78+
# If player lost tournament, ladder challenge ends
8079
break
8180

82-
rank = len(ladder) - idx
81+
print("=" * 10)
82+
print(
83+
f"{player['name']} successfully beat {opponent['name']} (rank {opponent_rank}/{len(ladder)}) "
84+
f"in {player_wins}/{len(round_winners)} rounds.\n"
85+
"Ladder challenge continuing"
86+
)
87+
print("=" * 10)
88+
8389
print(f"Ladder tournament complete. Logs saved to {parent_dir}")
84-
print(f"Final opponent faced: {opponent['name']} (rank {rank}/{len(ladder)} in ladder)")
90+
print(f"Final opponent faced: {opponent['name']} (rank {opponent_rank}/{len(ladder)} in ladder)")
8591

8692

8793
def main_cli(argv: list[str] | None = None):

0 commit comments

Comments
 (0)