Skip to content

Commit a4d71b9

Browse files
committed
Add dummy game
1 parent 13a0aca commit a4d71b9

5 files changed

Lines changed: 74 additions & 1 deletion

File tree

codeclash/games/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from codeclash.games.battlecode.main import BattleCodeGame
55
from codeclash.games.battlesnake.main import BattleSnakeGame
66
from codeclash.games.corewar.main import CoreWarGame
7+
from codeclash.games.dummy.main import DummyGame
78
from codeclash.games.robocode.main import RoboCodeGame
89
from codeclash.games.robotrumble.main import RobotRumbleGame
910

@@ -16,6 +17,7 @@ def get_game(config: dict, *, tournament_id: str, local_output_dir: Path) -> Cod
1617
BattleCodeGame,
1718
BattleSnakeGame,
1819
CoreWarGame,
20+
DummyGame,
1921
RoboCodeGame,
2022
RobotRumbleGame,
2123
]

codeclash/games/corewar/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ def execute_round(self, agents: list[Player]) -> RoundData:
5656
self.logger.info(f"Running game: {cmd}")
5757
response = self.environment.execute(cmd)
5858
assert response["returncode"] == 0, response
59-
return RoundData([response["output"]], [response["output"]])
59+
return RoundData(logs=[response["output"]], results=[response["output"]])

codeclash/games/dummy/main.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import re
2+
3+
from codeclash.agents.abstract import Player
4+
from codeclash.games.abstract import CodeGame, RoundData, RoundStats
5+
6+
7+
class DummyGame(CodeGame):
8+
name: str = "DummyGame"
9+
10+
def get_stats(self, result_outputs: list[str], agents: list[Player]) -> RoundStats:
11+
result_output = result_outputs[0] # Get the first (and only) element
12+
lines = result_output.split("FINAL_RESULTS")[-1].splitlines()
13+
14+
scores = {}
15+
for line in lines:
16+
match = re.search(r"Bot\_(\d)\_main:\s(\d+)\srounds\swon", line)
17+
if match:
18+
bot_id = match.group(1)
19+
rounds_won = int(match.group(2))
20+
scores[agents[int(bot_id) - 1].name] = rounds_won
21+
22+
return RoundStats(
23+
winner=max(scores, key=scores.get) if scores else "unknown",
24+
scores=scores,
25+
details={"dummy": True},
26+
)
27+
28+
def execute_round(self, agents: list[Player]) -> RoundData:
29+
args = [f"/{agent.name}/main.py" for agent in agents]
30+
cmd = f"python engine.py {' '.join(args)} -r {self.game_config['sims_per_round']}"
31+
self.logger.info(f"Running game: {cmd}")
32+
response = self.environment.execute(cmd)
33+
assert response["returncode"] == 0, response
34+
return RoundData(logs=[response["output"]], results=[response["output"]])

configs/dummy.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
game:
2+
name: DummyGame
3+
sims_per_round: 100
4+
tournament:
5+
rounds: 3
6+
players:
7+
- agent: dummy
8+
name: p1
9+
- agent: dummy
10+
name: p2
11+
prompts:
12+
game_description: |
13+
You are a software developer ({{player_id}}) competing in a coding game.
14+
15+
The game is played in {{rounds}} rounds. For every round, you (and your competitor) edit program code that controls your bot. This is round {{round}}.
16+
After you and your competitor finish editing your codebases, the game is run automatically.

docker/DummyGame.Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM ubuntu:22.04
2+
3+
ENV DEBIAN_FRONTEND=noninteractive \
4+
GO_VERSION=1.22.0 \
5+
PATH=/usr/local/go/bin:$PATH
6+
7+
# Install Python 3.10 (and alias python→python3.10), pip, and prerequisites
8+
RUN apt-get update \
9+
&& apt-get install -y --no-install-recommends \
10+
curl ca-certificates python3.10 python3.10-venv \
11+
python3-pip python-is-python3 wget git build-essential jq curl locales \
12+
&& rm -rf /var/lib/apt/lists/*
13+
14+
# Inject GitHub token for private repo access
15+
ARG GITHUB_TOKEN
16+
RUN git clone https://${GITHUB_TOKEN}@github.com/emagedoc/DummyGame.git /testbed \
17+
&& cd /testbed \
18+
&& git remote set-url origin https://github.com/emagedoc/DummyGame.git \
19+
&& unset GITHUB_TOKEN
20+
21+
WORKDIR /testbed

0 commit comments

Comments
 (0)