2121def _resolve_ladder_rules (ladder_rules : dict , rounds : int ) -> tuple [float , int ]:
2222 """Validate the optional ``ladder_rules`` block and return ``(min_round_win_fraction, win_last_k)``.
2323
24- Defaults reproduce the historical behavior: win a strict majority of rounds
25- (``min_round_win_fraction=0.5``) AND win the final round (``win_last_k=1``).
24+ Defaults: win at least ``min_round_win_fraction`` (0.4) of the *agent* rounds AND win the last
25+ ``win_last_k`` (1) round(s). The baseline round 0 (identical, un-edited codebases) is excluded
26+ from this count — it reflects game variance, not the agent — so the fraction is taken over the
27+ ``rounds`` rounds the agent actually edits.
2628 """
27- min_round_win_fraction = ladder_rules .get ("min_round_win_fraction" , 0.5 )
29+ min_round_win_fraction = ladder_rules .get ("min_round_win_fraction" , 0.4 )
2830 win_last_k = ladder_rules .get ("win_last_k" , 1 )
2931
3032 # win_last_k: number of trailing rounds the player must win (1 == just the final round).
@@ -40,14 +42,15 @@ def _resolve_ladder_rules(ladder_rules: dict, rounds: int) -> tuple[float, int]:
4042 typer .echo (f"ladder_rules.win_last_k ({ win_last_k } ) cannot exceed tournament.rounds ({ rounds } )." )
4143 raise typer .Exit (1 )
4244
43- # min_round_win_fraction: player must win strictly more than this fraction of rounds.
45+ # min_round_win_fraction: player must win >= this fraction of the agent rounds (round 0 excluded) .
4446 if isinstance (min_round_win_fraction , bool ) or not isinstance (min_round_win_fraction , (int , float )):
4547 typer .echo (f"ladder_rules.min_round_win_fraction must be a number, got { min_round_win_fraction !r} ." )
4648 raise typer .Exit (1 )
47- if not 0 <= min_round_win_fraction < 1 :
49+ if not 0 <= min_round_win_fraction <= 1 :
4850 typer .echo (
49- f"ladder_rules.min_round_win_fraction must be in [0, 1), got { min_round_win_fraction } . "
50- "0.5 requires a strict majority; 0 drops the majority requirement."
51+ f"ladder_rules.min_round_win_fraction must be in [0, 1], got { min_round_win_fraction } . "
52+ "The player must win >= this fraction of the agent rounds; 1 requires winning all of them, "
53+ "0 drops the fraction requirement."
5154 )
5255 raise typer .Exit (1 )
5356
@@ -145,8 +148,8 @@ def run(
145148 config .pop ("ladder_rules" , None )
146149
147150 print (
148- f"Ladder advancement rule: win > { min_round_win_fraction :.0%} of { rounds } rounds "
149- f"and win the last { win_last_k } round(s)."
151+ f"Ladder advancement rule: win >= { min_round_win_fraction :.0%} of { rounds } agent rounds "
152+ f"(baseline round 0 excluded) and win the last { win_last_k } round(s)."
150153 )
151154 ladder_folder = f"LadderTournament.{ config ['game' ]['name' ]} .r{ rounds } .s{ sims } .{ timestamp } "
152155 player ["branch" ] = ladder_folder
@@ -185,21 +188,21 @@ def run(
185188 metadata_path = tournament_dir / "metadata.json"
186189 with open (metadata_path ) as f :
187190 metadata = yaml .safe_load (f )
188- round_winners = [r ["winner" ] for r in metadata ["round_stats" ].values () ]
191+ round_winners = [r ["winner" ] for k , r in metadata ["round_stats" ].items () if int ( k ) != 0 ]
189192
190- # Advancement rule (configurable via `ladder_rules`): win strictly more than
191- # `min_round_win_fraction` of rounds AND win the last `win_last_k` rounds.
193+ # Advancement rule (configurable via `ladder_rules`): win at least
194+ # `min_round_win_fraction` of the agent rounds AND win the last `win_last_k` rounds.
192195 player_wins = sum (1 for w in round_winners if w == player ["name" ])
193- won_majority = player_wins > len (round_winners ) * min_round_win_fraction
196+ won_majority = player_wins >= len (round_winners ) * min_round_win_fraction
194197 won_last_k = all (w == player ["name" ] for w in round_winners [- win_last_k :])
195198
196199 if not won_majority or not won_last_k :
197200 # Player failed the advancement rule; the ladder challenge ends here.
198201 print ("=" * 10 )
199202 print (
200203 f"{ player ['name' ]} did not clear { opponent ['name' ]} "
201- f"(rank { opponent_rank } /{ len (ladder )} ): won { player_wins } /{ len (round_winners )} rounds "
202- f"(needed > { min_round_win_fraction :.0%} ), last { win_last_k } round(s) won: { won_last_k } .\n "
204+ f"(rank { opponent_rank } /{ len (ladder )} ): won { player_wins } /{ len (round_winners )} agent rounds "
205+ f"(needed >= { min_round_win_fraction :.0%} ), last { win_last_k } round(s) won: { won_last_k } .\n "
203206 "Ladder challenge ends."
204207 )
205208 print ("=" * 10 )
0 commit comments