Skip to content

DummyGame

Simple test game for development and debugging.

Overview

DummyGame is a minimal game implementation used for testing the CodeClash framework.

Implementation

codeclash.arenas.dummy.dummy.DummyArena

DummyArena(config: dict, *, tournament_id: str, local_output_dir: Path, keep_containers: bool = False)

Bases: CodeArena

Source code in codeclash/arenas/arena.py
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def __init__(self, config: dict, *, tournament_id: str, local_output_dir: Path, keep_containers: bool = False):
    """The CodeArena class is responsible for running games, i.e., taking a list of code
    from different agents/players and running them against each other.
    It also provides the environments for the game and agents to run in.

    The central method is `run_round`, which takes a list of agents and returns the winner of the round.

    At the end of the the tournament, run the `end` method to clean up the game and agents and write the metadata.

    Args:
        config: The overall config for the tournament.
        tournament_id: The id of the tournament.
        local_output_dir: The host/local directory to write logs to.
        keep_containers: Do not remove containers after games/agent finish.
    """
    self.url_gh: str = f"git@github.com:{GH_ORG}/{self.name}.git"
    self.artifacts: list[Path] = []
    """Artifact objects that we might want to clean up after the game."""
    self.config: dict = config
    self._keep_containers: bool = keep_containers
    self._metadata: dict = {
        "name": self.name,
        "config": self.config["game"],
        "game_id": tournament_id,
        "created_timestamp": int(time.time()),
    }
    self.log_env: Path = DIR_LOGS
    self.log_local: Path = local_output_dir
    self.logger = get_logger(self.name, log_path=self.log_local / "game.log", emoji="🏓")
    self.environment: DockerEnvironment = self.get_environment()
    """The running docker environment for executing the game"""

name class-attribute instance-attribute

name: str = 'Dummy'

description class-attribute instance-attribute

description: str = 'WARNING: This is a dummy game meant for testing the CodeClash infrastructure. It does not represent a real game.'

submission class-attribute instance-attribute

submission: str = 'main.py'

execute_round

execute_round(agents: list[Player]) -> None
Source code in codeclash/arenas/dummy/dummy.py
15
16
17
18
19
def execute_round(self, agents: list[Player]) -> None:
    args = [f"/{agent.name}/{self.submission}" for agent in agents]
    cmd = f"python engine.py {' '.join(args)} -r {self.game_config['sims_per_round']} > {self.log_env / DUMMY_LOG};"
    self.logger.info(f"Running game: {cmd}")
    assert_zero_exit_code(self.environment.execute(cmd))

get_results

get_results(agents: list[Player], round_num: int, stats: RoundStats)
Source code in codeclash/arenas/dummy/dummy.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def get_results(self, agents: list[Player], round_num: int, stats: RoundStats):
    with open(self.log_round(round_num) / DUMMY_LOG) as f:
        round_log = f.read()
    lines = round_log.split("FINAL_RESULTS")[-1].splitlines()

    scores = {}
    for line in lines:
        match = re.search(r"Bot\_(\d)\_main:\s(\d+)\srounds\swon", line)
        if match:
            bot_id = match.group(1)
            rounds_won = int(match.group(2))
            scores[agents[int(bot_id) - 1].name] = rounds_won

    stats.winner = max(scores, key=scores.get) if scores else "unknown"
    stats.scores = scores
    for player, score in scores.items():
        stats.player_stats[player].score = score

validate_code

validate_code(agent: Player) -> tuple[bool, str | None]
Source code in codeclash/arenas/dummy/dummy.py
39
40
41
def validate_code(self, agent: Player) -> tuple[bool, str | None]:
    # TODO: implement more checks
    return True, None

Usage

Useful for: - Testing tournament infrastructure - Debugging agent implementations - Quick validation of configurations

Configuration Example

game:
  name: DummyGame
  rounds: 3
  sims_per_round: 1

players:
  - name: TestAgent
    model: gpt-4