Skip to content

Commit dca3698

Browse files
committed
Add battlecode basic code
1 parent a278c30 commit dca3698

4 files changed

Lines changed: 50 additions & 4 deletions

File tree

codeclash/games/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from codeclash.games.abstract import CodeGame
2+
from codeclash.games.battlecode.main import BattleCodeGame
23
from codeclash.games.battlesnake.main import BattleSnakeGame
34
from codeclash.games.corewar.main import CoreWarGame
45
from codeclash.games.robocode.main import RoboCodeGame
@@ -8,10 +9,13 @@
89
# might consider postponing imports to avoid loading things we don't need
910
def get_game(config: dict) -> CodeGame:
1011
game = {
11-
BattleSnakeGame.name: BattleSnakeGame,
12-
CoreWarGame.name: CoreWarGame,
13-
RoboCodeGame.name: RoboCodeGame,
14-
RobotRumbleGame.name: RobotRumbleGame,
12+
x.name: x for x in [
13+
BattleCodeGame,
14+
BattleSnakeGame,
15+
CoreWarGame,
16+
RoboCodeGame,
17+
RobotRumbleGame
18+
]
1519
}.get(config["game"]["name"])
1620
if game is None:
1721
raise ValueError(f"Unknown game: {config['game']['name']}")

codeclash/games/battlecode/main.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from typing import Any
2+
3+
from codeclash.games.abstract import CodeGame
4+
5+
6+
class BattleCodeGame(CodeGame):
7+
name: str = "BattleCode"
8+
9+
def __init__(self, config):
10+
super().__init__(config)
11+
assert len(config["players"]) == 2, "BattleCode is a two-player game"
12+
self.run_cmd_round: str = "python run.py run"
13+
14+
def determine_winner(self, agents: list[Any]):
15+
response = self.environment.execute(f"tail -2 {self.round_log_path}")
16+
self.scoreboard.append((self.round, "BLAH")) # TODO
17+
18+
def execute_round(self, agents: list[Any]):
19+
args = [f"/{agent.name}/src/" for agent in agents]
20+
cmd = f"{self.run_cmd_round}" # TODO
21+
response = self.environment.execute(cmd)
22+
assert response["returncode"] == 0, response

configs/battlecode.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
game:
2+
name: BattleCode
3+
rounds: 2
4+
players:
5+
- agent: dummy
6+
name: p1
7+
- agent: dummy
8+
name: p2

docker/BattleCode.Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM python:3.12-slim-bookworm
2+
3+
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
4+
RUN apt-get update && apt-get install -y --no-install-recommends \
5+
build-essential git curl && \
6+
rm -rf /var/lib/apt/lists/*
7+
8+
RUN git clone https://github.com/emagedoc/BattleCode.git /testbed
9+
10+
WORKDIR /testbed
11+
12+
RUN python run.py update

0 commit comments

Comments
 (0)