MCPcopy Create free account
hub / github.com/CodeClash-ai/CodeClash / run

Function run

codeclash/cli/app.py:42–93  ·  view source on GitHub ↗

Run a PvP tournament from a config file. [dim]• codeclash run configs/test/battlesnake_pvp_test.yaml[/dim] [dim]• codeclash run path/to/config.yaml -c -o out/ # cleanup + custom output dir[/dim]

(
    config_path: Path = typer.Argument(..., help="Path to the tournament config file."),
    cleanup: bool = typer.Option(False, "--cleanup", "-c", help="Clean up the game environment after running."),
    output_dir: Path | None = typer.Option(None, "--output-dir", "-o", help="Output directory (default: logs/<user>)."),
    suffix: str = typer.Option("", "--suffix", "-s", help="Suffix for the output folder name (no leading dot)."),
    keep_containers: bool = typer.Option(
        False, "--keep-containers", "-k", help="Do not remove containers after games/agent finish."
    ),
)

Source from the content-addressed store, hash-verified

40
41@app.command()
42def run(
43 config_path: Path = typer.Argument(..., help="Path to the tournament config file."),
44 cleanup: bool = typer.Option(False, "--cleanup", "-c", help="Clean up the game environment after running."),
45 output_dir: Path | None = typer.Option(None, "--output-dir", "-o", help="Output directory (default: logs/<user>)."),
46 suffix: str = typer.Option("", "--suffix", "-s", help="Suffix for the output folder name (no leading dot)."),
47 keep_containers: bool = typer.Option(
48 False, "--keep-containers", "-k", help="Do not remove containers after games/agent finish."
49 ),
50):
51 """Run a PvP tournament from a config file.
52
53 [dim]• codeclash run configs/test/battlesnake_pvp_test.yaml[/dim]
54 [dim]• codeclash run path/to/config.yaml -c -o out/ # cleanup + custom output dir[/dim]
55 """
56 yaml_content = config_path.read_text()
57 preprocessed_yaml = resolve_includes(yaml_content, base_dir=CONFIG_DIR)
58 config = yaml.safe_load(preprocessed_yaml)
59
60 if "ladder_rules" in config:
61 raise typer.BadParameter(
62 "ladder_rules (min_round_wins, win_last_k, fast_forward, early_clinch) applies only to "
63 "`codeclash ladder run`, not `codeclash run`."
64 )
65
66 def get_output_path() -> Path:
67 if is_running_in_aws_batch():
68 # Offset timestamp by random seconds to avoid collisions
69 offset = random.randint(0, 600)
70 timestamp = time.strftime("%y%m%d%H%M%S", time.localtime(time.time() + offset))
71 else:
72 timestamp = time.strftime("%y%m%d%H%M%S")
73 rounds = config["tournament"]["rounds"]
74 transparent = config["tournament"].get("transparent", False)
75 sims = config["game"]["sims_per_round"]
76
77 players = [p["name"] for p in config["players"]]
78 p_num = len(players)
79 p_list = ".".join(sorted(players))
80 suffix_part = f".{suffix}" if suffix else ""
81 folder_name = (
82 f"PvpTournament.{config['game']['name']}.r{rounds}.s{sims}.p{p_num}.{p_list}{suffix_part}.{timestamp}"
83 )
84 if transparent:
85 folder_name += ".transparent"
86 if is_running_in_aws_batch():
87 _uuid = str(uuid.uuid4())
88 folder_name += f".{_uuid}-uuid"
89 if output_dir is None:
90 if is_running_in_aws_batch():
91 return LOCAL_LOG_DIR / "batch" / folder_name
92 else:
93 return LOCAL_LOG_DIR / getpass.getuser() / folder_name
94 else:
95 return output_dir / folder_name
96

Callers

nothing calls this directly

Calls 4

runMethod · 0.95
resolve_includesFunction · 0.90
PvpTournamentClass · 0.90
get_output_pathFunction · 0.85

Tested by

no test coverage detected