diff --git a/.github/workflows/games.yml b/.github/workflows/games.yml index ebee4f6..0753511 100644 --- a/.github/workflows/games.yml +++ b/.github/workflows/games.yml @@ -41,6 +41,7 @@ jobs: with: {python-version: '3.12'} - run: python -m pip install -e . - run: harbor run --game-suite minihack-balrog --standard --list + - run: harbor run --game-suite rocketleague --standard --list - run: python game_first_exam/tests/test_game_harbor.py fresh-clone-smoke: runs-on: ubuntu-latest @@ -77,8 +78,50 @@ jobs: name: fresh-clone-room-evidence path: jobs/ retention-days: 7 + browser-game-smoke: + runs-on: ubuntu-latest + timeout-minutes: 35 + strategy: + fail-fast: false + matrix: + include: + - {suite: rocketleague, control: rocketleague/concede} + steps: + - uses: actions/checkout@v4 + with: {persist-credentials: false} + - uses: actions/setup-python@v5 + with: {python-version: '3.12'} + - uses: docker/setup-docker-action@v5 + with: + version: v29.5.2 + set-host: true + daemon-config: '{"features":{"containerd-snapshotter":true}}' + - run: python -m pip install -e . + - name: Run the reference solution + env: + SUITE: ${{ matrix.suite }} + run: | + harbor run --game-suite "$SUITE" --standard -c configs/harbor/oracle.json \ + --jobs-dir "$PWD/jobs" --job-name browser-reference -y + python ci_checks/check-browser-game-result.py jobs/browser-reference 1 + - name: Run the failure control + env: + CONTROL: ${{ matrix.control }} + run: | + python "game_first_exam/tests/benchmarks/$CONTROL/run_harbor.py" + python ci_checks/check-browser-game-result.py jobs 0 + - uses: actions/upload-artifact@v4 + if: always() + with: + name: ${{ matrix.suite }}-smoke-evidence + path: | + jobs/*/result.json + jobs/*/*/artifacts/data/final.json + jobs/*/*/verifier/reward.json + jobs/*/*/trial.log + retention-days: 7 invariants: - needs: [static, adapters, harbor, fresh-clone-smoke] + needs: [static, adapters, harbor, fresh-clone-smoke, browser-game-smoke] if: ${{ always() }} runs-on: ubuntu-latest steps: @@ -87,4 +130,5 @@ jobs: ADAPTERS: ${{ needs.adapters.result }} HARBOR: ${{ needs.harbor.result }} SMOKE: ${{ needs.fresh-clone-smoke.result }} - run: test "$STATIC" = success && test "$ADAPTERS" = success && test "$HARBOR" = success && test "$SMOKE" = success + BROWSER_SMOKE: ${{ needs.browser-game-smoke.result }} + run: test "$BROWSER_SMOKE" = success && test "$STATIC" = success && test "$ADAPTERS" = success && test "$HARBOR" = success && test "$SMOKE" = success diff --git a/ci_checks/check-browser-game-result.py b/ci_checks/check-browser-game-result.py new file mode 100644 index 0000000..e37df34 --- /dev/null +++ b/ci_checks/check-browser-game-result.py @@ -0,0 +1,25 @@ +"""Verify the Harbor verdict from a browser game's reference or control run.""" +import json +import sys +from pathlib import Path + + +def check(trial_dir, expected): + paths = ( + trial_dir.glob("*/verifier/reward.json") if expected == 1 else + (path for path in trial_dir.glob("*/*/verifier/reward.json") + if path.parents[2].name != "browser-reference") + ) + rewards = list(paths) + if len(rewards) != 1: + raise ValueError(f"Expected one verifier result under {trial_dir}, found {len(rewards)}") + reward = json.loads(rewards[0].read_text()) + errors = ("infra_error", "sim_error", "environment_error") + if (not reward.get("result_valid") or any(reward.get(key) != 0 for key in errors) + or reward.get("steps", 0) <= 0 or reward.get("success") != expected): + raise ValueError(f"Expected a valid result with success={expected}: {reward}") + print(f"{rewards[0]}: success={expected}, steps={reward['steps']}") + + +if __name__ == "__main__": + check(Path(sys.argv[1]), int(sys.argv[2])) diff --git a/configs/game_benchmarks.toml b/configs/game_benchmarks.toml index 8f77b59..1c01c3c 100644 --- a/configs/game_benchmarks.toml +++ b/configs/game_benchmarks.toml @@ -14,3 +14,6 @@ schema = "game_first_exam/benchmarks/babaisai/instance_schema.py" [benchmarks.minihack] schema = "game_first_exam/benchmarks/minihack/instance_schema.py" + +[benchmarks.rocketleague] +schema = "game_first_exam/benchmarks/rocketleague/instance_schema.py" diff --git a/configs/game_suites/rocketleague.toml b/configs/game_suites/rocketleague.toml new file mode 100644 index 0000000..d8b621f --- /dev/null +++ b/configs/game_suites/rocketleague.toml @@ -0,0 +1,10 @@ +schema_version = "game-suite/2.1" +version = "1.0.0" +tier = "smoke" +name = "games-rocketleague-minimal-v1.0.0" +files_images = ["connection-files", "game-files", "rocketleague-files"] + +[[tasks]] +name = "rocketleague-first-goal-i01-standard" +benchmark = "rocketleague" +family = "first-goal" diff --git a/docs/demos/rocketleague/conceded-goal.mp4 b/docs/demos/rocketleague/conceded-goal.mp4 new file mode 100644 index 0000000..e472e9d Binary files /dev/null and b/docs/demos/rocketleague/conceded-goal.mp4 differ diff --git a/docs/demos/rocketleague/first-goal.mp4 b/docs/demos/rocketleague/first-goal.mp4 new file mode 100644 index 0000000..8b0433d Binary files /dev/null and b/docs/demos/rocketleague/first-goal.mp4 differ diff --git a/game_first_exam/benchmarks/rocketleague/adapter.py b/game_first_exam/benchmarks/rocketleague/adapter.py new file mode 100644 index 0000000..2f5c512 --- /dev/null +++ b/game_first_exam/benchmarks/rocketleague/adapter.py @@ -0,0 +1,125 @@ +"""GameWorld 25_01, played against the native single-player opponent.""" +from base64 import b64decode +from contextlib import ExitStack +from datetime import datetime, timedelta, timezone +from io import BytesIO +from pathlib import Path +from urllib.parse import unquote, urlsplit + +import numpy as np +from PIL import Image +from playwright.sync_api import sync_playwright + +from contracts import Capabilities, Transition +from encoding import png, state_hash + +MOVES = {"wait": (), "left": ("a",), "right": ("d",), "brake": ("s",), + "jump": ("w",), "jump_left": ("a", "w"), "jump_right": ("d", "w"), + "boost_left": ("a", "Space"), "boost_right": ("d", "Space"), + "jump_boost_right": ("d", "w", "Space"), "jump_boost_left": ("a", "w", "Space")} +ORIGIN = "http://pitch.test" + + +class Adapter: + def __init__(self, instance, assets=None): + self.stack = ExitStack() + try: + self.load(Path(assets) / "game") + except BaseException: + self.close() + raise + + def load(self, root): + root = root.resolve(strict=True) + driver = self.stack.enter_context(sync_playwright()) + browser = driver.chromium.launch(args=["--mute-audio"]) + self.stack.callback(browser.close) + self.page = browser.new_page(viewport={"width": 1024, "height": 384}) + + self.cdp = self.page.context.new_cdp_session(self.page) + + def serve(route): + url = urlsplit(route.request.url) + path = (root / unquote(url.path).lstrip("/")).resolve() + if url.netloc == "pitch.test" and path.is_relative_to(root) and path.is_file(): + route.fulfill(path=path) + else: + route.abort() + + self.page.route("**/*", serve) + start = datetime(2026, 1, 1, tzinfo=timezone.utc) + self.page.clock.install(time=start) + self.page.clock.pause_at(start + timedelta(seconds=1)) + self.page.goto(ORIGIN + "/index.html?player=1", wait_until="domcontentloaded") + # Stop on the first playable animation frame, including on a cold browser cache. + for _ in range(2500): + self.page.clock.run_for(16) + state = self.page.evaluate("() => window.gameAPI?.getState()") + if state and state["is_actionable"]: + if state["game_state"]["environment"]["room_name"] == "rm_game": + self.state = state + break + else: + raise RuntimeError("Single-player match did not start") + if self.score() != (0, 0) or self.state["seed"] != 42: + raise RuntimeError("Unexpected kickoff") + self.steps = 0 + self.capture() + + def spec(self): + return {"adapter_version": "1.0.0", "capabilities": Capabilities(True, "enum").to_dict(), + "action_schema": {"type": "string", "enum": list(MOVES)}, + "actions": "Hold one movement for 160 milliseconds of match time.", + "goal": "Score the first goal against the native AI."} + + def capture(self): + # DevTools captures the composited frame without advancing the paused game clock. + shot = self.cdp.send("Page.captureScreenshot", {"format": "png", "fromSurface": True}) + data = b64decode(shot["data"]) + with Image.open(BytesIO(data)) as image: + self.rgb = np.array(image.convert("RGB")) + + def frame(self): + return self.rgb + + def observe(self): + return {"image_png_base64": png(self.rgb)} + + def step(self, action): + if action not in MOVES or self.score() != (0, 0): + raise ValueError("Invalid input or finished match") + keys = MOVES[action] + for key in keys: + self.page.keyboard.down(key) + try: + self.page.clock.run_for(160) + finally: + for key in reversed(keys): + self.page.keyboard.up(key) + self.steps += 1 + self.state = self.page.evaluate("gameAPI.getState()") + self.capture() + return Transition(float(self.success()), self.score() != (0, 0)) + + def score(self): + metrics = self.state["metrics"] + score = metrics["goals_for"], metrics["goals_against"] + if any(type(value) is not int for value in score): + raise RuntimeError("Native scoreboard unavailable") + return score + + def success(self): + return self.score() == (1, 0) + + def metrics(self): + own, opponent = self.score() + return {"goals_for": own, "goals_against": opponent, "success": int(self.success())} + + def fingerprint(self): + board = self.state["game_state"] + return state_hash({"seed": self.state["seed"], "room": board["environment"]["room_name"], + "player": board["player"], "entities": board["entities"], + "score": self.score(), "steps": self.steps}) + + def close(self): + self.stack.close() diff --git a/game_first_exam/benchmarks/rocketleague/instance_schema.py b/game_first_exam/benchmarks/rocketleague/instance_schema.py new file mode 100644 index 0000000..8e6fb4e --- /dev/null +++ b/game_first_exam/benchmarks/rocketleague/instance_schema.py @@ -0,0 +1,13 @@ +SCHEMA_VERSION = "1.0.0" +BENCHMARK = "rocketleague" +FIELDS = {"engine_commit"} +METRICS = {"success"} +PROFILES = {"native-rgb-v1"} +REDUCERS = {("family_macro", "1.0.0")} + + +def validate(value): + if value["seed"] != 42 or value["engine_commit"] != "e5ddb16df85b91a1d17bb0577621cc7c5e65d738": + raise ValueError("unknown GameWorld-Games version") + if (value["env_id"], value["family"], value["max_steps"]) != ("rocket-league-2d", "first-goal", 250): + raise ValueError("unknown GameWorld task configuration") diff --git a/game_first_exam/benchmarks/rocketleague/metric_rules.py b/game_first_exam/benchmarks/rocketleague/metric_rules.py new file mode 100644 index 0000000..4c5701c --- /dev/null +++ b/game_first_exam/benchmarks/rocketleague/metric_rules.py @@ -0,0 +1,11 @@ +"""Grade GameWorld 25_01 at the first goal.""" +def validate_metrics(final, instance): + metrics = final["metrics"] + score = metrics["goals_for"], metrics["goals_against"] + if any(type(goals) is not int for goals in score) or score not in {(0, 0), (1, 0), (0, 1)}: + raise ValueError("Invalid first-goal score") + won = score == (1, 0) + if final["terminated"] != (score != (0, 0)): + raise ValueError("Terminal flag disagrees with the scoreboard") + if (final["success"], final["return"], metrics["success"]) != (won, float(won), int(won)): + raise ValueError("Reward disagrees with the scoreboard") diff --git a/game_first_exam/benchmarks/rocketleague/requirements.txt b/game_first_exam/benchmarks/rocketleague/requirements.txt new file mode 100644 index 0000000..70da3b9 --- /dev/null +++ b/game_first_exam/benchmarks/rocketleague/requirements.txt @@ -0,0 +1,5 @@ +playwright==1.55.0 +numpy==1.26.4 +pillow==10.4.0 +imageio-ffmpeg==0.6.0 +imageio==2.37.0 diff --git a/game_first_exam/images/rocketleague-files/FILES.json b/game_first_exam/images/rocketleague-files/FILES.json new file mode 100644 index 0000000..d024802 --- /dev/null +++ b/game_first_exam/images/rocketleague-files/FILES.json @@ -0,0 +1,10 @@ +{ + "source": "game_first_exam/benchmarks/rocketleague", + "files": { + "adapter.py": "e7cbea18f41b22cb04a21d2f9dec5dfb09a6871162e5f843fd9c76106584dde6", + "instance_schema.py": "71b9f199ea60d7f63cecb7cd19120adbe717eaaf3a683332062392cce9621f74", + "metric_rules.py": "c51413a27a70ad20505cb3e200e61ae0566c0a4e67d6889266d018fb290fdfb0", + "requirements.txt": "f7b63cd5e9d2d806613a620bb7340f27ce6735ba76c9d5a08f77d48e527d4733" + }, + "image": "ghcr.io/mll-lab-nu/efe:rocketleague-files-0.1.0@sha256:d3ae7d1cd943106acd92ecfebea6aa43660877adab9b0c2243dfb90eaa4235c2" +} diff --git a/game_first_exam/images/rocketleague-files/VERSION b/game_first_exam/images/rocketleague-files/VERSION new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/game_first_exam/images/rocketleague-files/VERSION @@ -0,0 +1 @@ +0.1.0 diff --git a/game_first_exam/tasks/rocketleague/README.md b/game_first_exam/tasks/rocketleague/README.md new file mode 100644 index 0000000..722adca --- /dev/null +++ b/game_first_exam/tasks/rocketleague/README.md @@ -0,0 +1,20 @@ +# Rocket League 2D +GameWorld task 25_01 asks the player to score without conceding. This adapter ends the match at its first goal and checks both native goal counters. The simulator builds the original single-player game from its pinned upstream commit and uses its default AI. Only screenshots and player-one keyboard actions cross the client interface. + +Run the reference attack and the early-release control from the repository root. + +```sh +harbor run --game-suite rocketleague --standard -a oracle -y +python game_first_exam/tests/benchmarks/rocketleague/concede/run_harbor.py +``` + +[GameWorld task](https://github.com/gameworld-project/GameWorld/blob/84f624bd1e120d30aeebf2eb42a39410e24d3bd4/catalog/tasks/25_rocket-league-2d/25_01.yaml) · [Game assets and rights](https://github.com/gameworld-project/GameWorld-Games/tree/e5ddb16df85b91a1d17bb0577621cc7c5e65d738/benchmark/25_rocket-league-2d) + +## Gameplay demos + +| Player input | Score | Steps | Harbor reward | +| --- | --- | ---: | ---: | +| [Hold boost to the right](../../../docs/demos/rocketleague/first-goal.mp4) | 1–0 | 31 | 1 | +| [Release boost after eight steps](../../../docs/demos/rocketleague/conceded-goal.mp4) | 0–1 | 172 | 0 | + +Both Harbor trials completed with zero environment errors. Their FFmpeg recording pipes closed early. The linked videos are separate browser runs of the same policies, with matching opening fingerprints, final scores and action counts. diff --git a/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/DIGEST b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/DIGEST new file mode 100644 index 0000000..0ba5687 --- /dev/null +++ b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/DIGEST @@ -0,0 +1 @@ +sha256:dc3aa7135cd4562c5d4f019c2235340aee43d76e8cba3480e0ef1e72e9fae911 diff --git a/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/README.md b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/README.md new file mode 100644 index 0000000..1cdaa9a --- /dev/null +++ b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/README.md @@ -0,0 +1,35 @@ +# rocketleague-first-goal-i01-standard + +| | | +|---|---| +| Benchmark | GameWorld Rocket League 2D | +| Mode | standard (`game-standard/2.2`) | +| Twin | — (none: GameWorld Rocket League 2D has no privileged mode, PROTOCOL §2) | +| Simulator / robot | `rocketleague` / `game-agent` | +| Family / instance | `first-goal` / seed 42 | +| Oracle | `full` | +| Agent time budget | 600 s; tokens: protocol default (docs/protocol/running.md "Official runs") | +| Base image | `docker.io/library/python:3.12.10-slim-bookworm@sha256:fd95fa221297a88e1cf49c55ec1828edd7c5a428187e67b5d1805692d11588db` | + +## Task +Score first in a single-player match against the native AI. The reference solution drives and boosts through the public client. The verifier checks both teams’ goal counts. + +## Difficulty +Start at a fixed kickoff against the default single-player opponent. Releasing boost early gives the opponent time to recover and counterattack. + +## Reference solution +See `solution/`. + +## Verification +The verifier checks the two native goal counters. A first goal for the player earns one point. Conceding or exhausting the action budget earns zero. + +## Resources +Caps per container (PROTOCOL §6). + +| Container | CPUs | Memory | Processes | GPU memory | Disk | +|---|---|---|---|---|---| +| `main` (the agent's) | 1 | 1 GiB | 256 | no GPU | 2 GiB | +| `sim` | 1 | 1 GiB | 128 | no GPU | — | +| verifier (as `main`) | 1 | 1 GiB | no cap | no GPU | 2 GiB | + +- GPU: not needed. diff --git a/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/environment/Dockerfile b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/environment/Dockerfile new file mode 100644 index 0000000..10dcc84 --- /dev/null +++ b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/environment/Dockerfile @@ -0,0 +1,9 @@ +FROM docker.io/library/python:3.12.10-slim-bookworm@sha256:fd95fa221297a88e1cf49c55ec1828edd7c5a428187e67b5d1805692d11588db +RUN apt-get update && apt-get install -y --no-install-recommends bash curl git nodejs npm ca-certificates \ + && rm -rf /var/lib/apt/lists/* +RUN npm install -g @openai/codex@0.167.1 && npm cache clean --force +COPY --from=ghcr.io/mll-lab-nu/efe:game-files-0.6.0@sha256:bfb708928954d5cc194a614ab772a65b1e56f381b49dfeb2227c3d609e5f2ecc /game_client.py /app/game_client.py +COPY --from=ghcr.io/mll-lab-nu/efe:connection-files-0.1.0@sha256:6d1002dea6ca507b4148d3196e233838e645b33bcfa9a27ae4a43027ae519999 /service_connection.py /app/service_connection.py +ENV PYTHONUNBUFFERED=1 PYTHONPATH=/app +RUN mkdir -p /app/output +WORKDIR /app diff --git a/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/environment/docker-compose.yaml b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/environment/docker-compose.yaml new file mode 100644 index 0000000..7fa17b4 --- /dev/null +++ b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/environment/docker-compose.yaml @@ -0,0 +1,43 @@ +services: + main: + pids_limit: 256 # rcb-monitor + volumes: # rcb-monitor + - rcb_limits:/run/rcb-limits:ro # rcb-monitor + depends_on: [sim] + sim: + cpus: 1 # rcb-monitor + mem_limit: 1024m # rcb-monitor + pids_limit: 128 # rcb-monitor + volumes: # rcb-monitor + - rcb_observe:/run/rcb-observe:ro # rcb-monitor + build: + context: sim + dockerfile: Dockerfile + working_dir: /srv + command: python3 /srv/server.py + environment: + RCB_WALL_CLOCK_S: "600" + # >>> rcb_monitor (resource monitor, PROTOCOL §6; generated by images/monitor/rcb_monitor/inject.py) + rcb_monitor: + image: ghcr.io/mll-lab-nu/efe:monitor-0.5.0@sha256:ecc5f24f1516ca11711d7c2d3ac07c89f79cd9220812c1244498ec71e352402a + pid: host + cgroup: host + network_mode: none + cap_add: [SYS_PTRACE] + cpus: 0.5 + mem_limit: 256m + pids_limit: 64 + restart: on-failure + working_dir: /var/rcb-monitor + volumes: + - ./rcb_monitor/limits.json:/opt/rcb_monitor/limits.json:ro + - rcb_limits:/run/rcb-limits + - rcb_observe:/run/rcb-observe + environment: + RCB_LIMITS_ENFORCE: ${RCB_LIMITS_ENFORCE:-0} + RCB_LIMITS_TOLERANCE: ${RCB_LIMITS_TOLERANCE:-0.05} + command: ["python3", "/opt/rcb_monitor/monitor.py", "run"] + # <<< rcb_monitor +volumes: # rcb-monitor + rcb_limits: # rcb-monitor + rcb_observe: # rcb-monitor diff --git a/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/environment/rcb_monitor/limits.json b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/environment/rcb_monitor/limits.json new file mode 100644 index 0000000..68f1045 --- /dev/null +++ b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/environment/rcb_monitor/limits.json @@ -0,0 +1,26 @@ +{ + "agent_timeout_sec": 600, + "caps": { + "main": { + "cpus": 1.0, + "disk_gb": 2.0, + "memory_gb": 1.0, + "pids": 256 + }, + "sim": { + "cpus": 1.0, + "memory_gb": 1.0, + "pids": 128 + } + }, + "disk_gb": 2.0, + "disk_tick_sec": 60, + "format": "rcb-limits/2", + "gpu": false, + "mode": "standard", + "scope_services": [ + "main" + ], + "task": "rocketleague-first-goal-i01-standard", + "tick_sec": 5 +} diff --git a/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/environment/sim/Dockerfile b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/environment/sim/Dockerfile new file mode 100644 index 0000000..cdd79eb --- /dev/null +++ b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/environment/sim/Dockerfile @@ -0,0 +1,18 @@ +FROM docker.io/library/python:3.12.10-slim-bookworm@sha256:fd95fa221297a88e1cf49c55ec1828edd7c5a428187e67b5d1805692d11588db +ENV PYTHONUNBUFFERED=1 +COPY --from=ghcr.io/mll-lab-nu/efe:rocketleague-files-0.1.0@sha256:d3ae7d1cd943106acd92ecfebea6aa43660877adab9b0c2243dfb90eaa4235c2 /requirements.txt /srv/requirements.txt +RUN apt-get update && apt-get install -y --no-install-recommends git ca-certificates && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir -r /srv/requirements.txt +COPY --from=ghcr.io/mll-lab-nu/efe:game-files-0.6.0@sha256:bfb708928954d5cc194a614ab772a65b1e56f381b49dfeb2227c3d609e5f2ecc /server.py /srv/server.py +COPY --from=ghcr.io/mll-lab-nu/efe:game-files-0.6.0@sha256:bfb708928954d5cc194a614ab772a65b1e56f381b49dfeb2227c3d609e5f2ecc /reducers.py /srv/reducers.py +COPY --from=ghcr.io/mll-lab-nu/efe:game-files-0.6.0@sha256:bfb708928954d5cc194a614ab772a65b1e56f381b49dfeb2227c3d609e5f2ecc /config_schema.py /srv/config_schema.py +COPY --from=ghcr.io/mll-lab-nu/efe:game-files-0.6.0@sha256:bfb708928954d5cc194a614ab772a65b1e56f381b49dfeb2227c3d609e5f2ecc /contracts.py /srv/contracts.py +COPY --from=ghcr.io/mll-lab-nu/efe:game-files-0.6.0@sha256:bfb708928954d5cc194a614ab772a65b1e56f381b49dfeb2227c3d609e5f2ecc /encoding.py /srv/encoding.py +COPY --from=ghcr.io/mll-lab-nu/efe:game-files-0.6.0@sha256:bfb708928954d5cc194a614ab772a65b1e56f381b49dfeb2227c3d609e5f2ecc /recording.py /srv/recording.py +COPY --from=ghcr.io/mll-lab-nu/efe:rocketleague-files-0.1.0@sha256:d3ae7d1cd943106acd92ecfebea6aa43660877adab9b0c2243dfb90eaa4235c2 /adapter.py /srv/adapter.py +RUN python -m playwright install --with-deps --only-shell chromium +RUN git init /tmp/upstream && cd /tmp/upstream && git remote add origin https://github.com/gameworld-project/GameWorld-Games.git && git sparse-checkout init --cone && git sparse-checkout set benchmark/25_rocket-league-2d && git fetch --depth=1 --filter=blob:none origin e5ddb16df85b91a1d17bb0577621cc7c5e65d738 && git checkout --detach FETCH_HEAD && mv benchmark/25_rocket-league-2d /srv/game && rm -rf /tmp/upstream +COPY --from=ghcr.io/mll-lab-nu/efe:rocketleague-files-0.1.0@sha256:d3ae7d1cd943106acd92ecfebea6aa43660877adab9b0c2243dfb90eaa4235c2 /instance_schema.py /srv/instance_schema.py +COPY instance.json /srv/instance.json +WORKDIR /srv +CMD ["python3", "/srv/server.py"] diff --git a/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/environment/sim/instance.json b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/environment/sim/instance.json new file mode 100644 index 0000000..741474f --- /dev/null +++ b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/environment/sim/instance.json @@ -0,0 +1,25 @@ +{ + "schema_version": "game-instance/2.2", + "protocol": "game-standard/2.2", + "adapter_version": "1.0.0", + "capabilities": { + "images": true, + "action_mode": "enum", + "timing": "action-stepped", + "native_truncation": false + }, + "benchmark": "rocketleague", + "env_id": "rocket-league-2d", + "family": "first-goal", + "seed": 42, + "max_steps": 250, + "engine_commit": "e5ddb16df85b91a1d17bb0577621cc7c5e65d738", + "initial_state_sha256": "738e3973516166a125771c63ea778431fea194a28bb7f6bb13d13047a9705455", + "observation_profile": "native-rgb-v1", + "metric_spec": { + "primary": "success", + "reducer": "family_macro", + "reducer_version": "1.0.0", + "success_label": "first_goal" + } +} diff --git a/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/instruction.md b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/instruction.md new file mode 100644 index 0000000..2a5e90f --- /dev/null +++ b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/instruction.md @@ -0,0 +1,29 @@ +# Rocket League 2D + +Score the first goal against the computer. The first goal ends the episode. A 1–0 score earns one point. Conceding first or reaching the 250-action limit without scoring earns zero. + +Read the current RGB screenshot using GameClient.save_image(). Each action holds the controls for 160 milliseconds of game time. The match pauses between decisions. Use wait, left, right, brake, jump, jump_left, jump_right, boost_left, boost_right, jump_boost_left or jump_boost_right. + +Use the live service through `/app/game_client.py`: + +```python +from game_client import GameClient +game = GameClient() +print(game.spec()) +obs = game.observe() +print(obs["observation"]) +# obs = game.step(action, expected_step=obs["step"]) +``` + +The public envelope contains step, done, steps_remaining and time_left_s. Each action requires the current expected_step and a request_id; the client creates an ID if omitted. Retry a lost response only with the same ID and identical payload. The service deduplicates it without advancing the environment again. Only spec, observe, status and submit are available. Agent-written output files do not determine scores. + +## External material +The network is open. You may install packages (pip, apt), and you may search for, download and use public tools, robot models and pretrained controllers: finding existing work and adapting it to this task is encouraged. Say in your notes what you used. You may read anything installed in your container, this benchmark's own source code included. The one thing not to look up is a ready-made solution to this exact task, such as this benchmark's reference solutions. This is an honour rule; trials are reviewed. + +## Resources +Your container: **1 CPUs**, **1 GiB of memory**, **256 processes and threads** and **2 GiB** of disk (new files under `/app`, `/tmp` and `/root`). Your container has no GPU. The simulator runs in its own container and does not count against these. CPU only slows you down; a process that goes over any other cap can be killed. Usage and caps: `/run/rcb-limits/usage.json`. + +## Time limit +You have 600 seconds to complete this task. Do not cheat by using online solutions or hints specific to this task. + +This is wall-clock time from the start of your session; the time you wait for the simulator service counts. When it is up you are stopped without warning and the episode is graded as it stands at that moment. The service's `time_left_s` counts the same limit from your first request to the service, so it never runs out before your time does: your real time left is `time_left_s` minus the time you spent before that request. Plan by it. Your session started when you received this task. `/run/rcb-limits/usage.json`, rewritten every few seconds, gives the time left on this limit (`time_left_s`) and its end (`deadline_utc`), counted from a little before your session started, so it never gives you more time than you have: read it (or run `date`) before you decide that time is short, never guess. Waiting counts too: a tool call that sends input to a process that keeps running (an interactive interpreter, a simulator loop, a server) can wait for the whole wait or yield time you give it even when the answer is printed at once, so give such calls a short wait and poll again if the output is not complete, or run one-shot scripts that exit when they are done. Installing packages is not cheating (`## External material` above). diff --git a/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/solution/solve.py b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/solution/solve.py new file mode 100644 index 0000000..c7aee09 --- /dev/null +++ b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/solution/solve.py @@ -0,0 +1,6 @@ +from game_client import GameClient + +game = GameClient() +state = game.observe() +while not state["done"]: + state = game.step("boost_right", expected_step=state["step"]) diff --git a/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/solution/solve.sh b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/solution/solve.sh new file mode 100755 index 0000000..a856bf7 --- /dev/null +++ b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/bash +set -euo pipefail +exec python3 /solution/solve.py diff --git a/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/task.toml b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/task.toml new file mode 100644 index 0000000..a9e015d --- /dev/null +++ b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/task.toml @@ -0,0 +1,59 @@ +schema_version = "1.3" +artifacts = [{ source = "/var/rcb-monitor/", service = "rcb_monitor" }, + { source = "/data/final.json", service = "sim" }, + { source = "/data/episode.jsonl", service = "sim" }, + { source = "/data/recording.json", service = "sim" }, + { source = "/data/replay.mp4", service = "sim" }, + { source = "/data/replay.last.png", service = "sim" }, + "/app/output/", +] + +[task] +name = "embodied-first-exam/rocketleague-first-goal-i01-standard" +description = "Score the first goal against the native single-player opponent." +keywords = ["game", "rocketleague", "sports", "soccer", "standard-mode"] + +[metadata] +task_type = "trajectory" +simulator = "rocketleague" +robot = "game-agent" +family = "first-goal" +dynamics = "static" +protocol = "game-standard/2.2" +oracle = "full" +instance_seed = 42 +expert_time_estimate_hours = 0.5 + +[verifier] +timeout_sec = 120.0 +environment_mode = "separate" +network_mode = "no-network" + +# Resources (PROTOCOL §6): seal the monitor's record first. +[[verifier.collect]] +service = "rcb_monitor" +command = "python3 /opt/rcb_monitor/monitor.py seal --wait 90" +timeout_sec = 120 + +[[verifier.collect]] +service = "main" +command = "kill -9 -1 2>/dev/null; exit 0" +timeout_sec = 30 + +[[verifier.collect]] +service = "sim" +command = "kill -USR1 $(cat /data/server.pid); i=0; while [ ! -f /data/collection.ready ] && [ $i -lt 30 ]; do sleep 1; i=$((i+1)); done; test -f /data/collection.ready && test -f /data/final.json" +timeout_sec = 40 + +[agent] +timeout_sec = 600.0 +network_mode = "public" + +[environment] +build_timeout_sec = 1200.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 + +[verifier.env] +RCB_LIMITS_ENFORCE = "${RCB_LIMITS_ENFORCE:-0}" diff --git a/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/tests/Dockerfile b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/tests/Dockerfile new file mode 100644 index 0000000..dd65ec2 --- /dev/null +++ b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/tests/Dockerfile @@ -0,0 +1,11 @@ +FROM docker.io/library/python:3.12.10-slim-bookworm@sha256:fd95fa221297a88e1cf49c55ec1828edd7c5a428187e67b5d1805692d11588db +COPY test.sh instance.json /tests/ +COPY --from=ghcr.io/mll-lab-nu/efe:game-files-0.6.0@sha256:bfb708928954d5cc194a614ab772a65b1e56f381b49dfeb2227c3d609e5f2ecc /grade.py /tests/grade.py +COPY --from=ghcr.io/mll-lab-nu/efe:game-files-0.6.0@sha256:bfb708928954d5cc194a614ab772a65b1e56f381b49dfeb2227c3d609e5f2ecc /reducers.py /tests/reducers.py +COPY --from=ghcr.io/mll-lab-nu/efe:game-files-0.6.0@sha256:bfb708928954d5cc194a614ab772a65b1e56f381b49dfeb2227c3d609e5f2ecc /config_schema.py /tests/config_schema.py +COPY --from=ghcr.io/mll-lab-nu/efe:rocketleague-files-0.1.0@sha256:d3ae7d1cd943106acd92ecfebea6aa43660877adab9b0c2243dfb90eaa4235c2 /instance_schema.py /tests/instance_schema.py +COPY --from=ghcr.io/mll-lab-nu/efe:rocketleague-files-0.1.0@sha256:d3ae7d1cd943106acd92ecfebea6aa43660877adab9b0c2243dfb90eaa4235c2 /metric_rules.py /tests/metric_rules.py +RUN chmod +x /tests/test.sh +# resources (PROTOCOL §6) # rcb-monitor +COPY --from=ghcr.io/mll-lab-nu/efe:monitor-0.5.0@sha256:ecc5f24f1516ca11711d7c2d3ac07c89f79cd9220812c1244498ec71e352402a /opt/rcb_monitor/rcb_limits.py /tests/rcb_limits.py +COPY rcb_limits.json /tests/rcb_limits.json diff --git a/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/tests/instance.json b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/tests/instance.json new file mode 100644 index 0000000..741474f --- /dev/null +++ b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/tests/instance.json @@ -0,0 +1,25 @@ +{ + "schema_version": "game-instance/2.2", + "protocol": "game-standard/2.2", + "adapter_version": "1.0.0", + "capabilities": { + "images": true, + "action_mode": "enum", + "timing": "action-stepped", + "native_truncation": false + }, + "benchmark": "rocketleague", + "env_id": "rocket-league-2d", + "family": "first-goal", + "seed": 42, + "max_steps": 250, + "engine_commit": "e5ddb16df85b91a1d17bb0577621cc7c5e65d738", + "initial_state_sha256": "738e3973516166a125771c63ea778431fea194a28bb7f6bb13d13047a9705455", + "observation_profile": "native-rgb-v1", + "metric_spec": { + "primary": "success", + "reducer": "family_macro", + "reducer_version": "1.0.0", + "success_label": "first_goal" + } +} diff --git a/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/tests/rcb_limits.json b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/tests/rcb_limits.json new file mode 100644 index 0000000..68f1045 --- /dev/null +++ b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/tests/rcb_limits.json @@ -0,0 +1,26 @@ +{ + "agent_timeout_sec": 600, + "caps": { + "main": { + "cpus": 1.0, + "disk_gb": 2.0, + "memory_gb": 1.0, + "pids": 256 + }, + "sim": { + "cpus": 1.0, + "memory_gb": 1.0, + "pids": 128 + } + }, + "disk_gb": 2.0, + "disk_tick_sec": 60, + "format": "rcb-limits/2", + "gpu": false, + "mode": "standard", + "scope_services": [ + "main" + ], + "task": "rocketleague-first-goal-i01-standard", + "tick_sec": 5 +} diff --git a/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/tests/test.sh b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/tests/test.sh new file mode 100755 index 0000000..0cf878a --- /dev/null +++ b/game_first_exam/tasks/rocketleague/rocketleague-first-goal-i01-standard/tests/test.sh @@ -0,0 +1,6 @@ +#!/bin/bash +rm -rf /logs/verifier/* +trap 'p=$(command -v python3 || command -v python); "$p" /tests/rcb_limits.py verify' EXIT # resources, after the grader (PROTOCOL §6) +p=$(command -v python3 || command -v python); "$p" /tests/rcb_limits.py sanitize /app/output || true # untrusted agent files (PROTOCOL H.1) +mkdir -p /logs/verifier +python3 /tests/grade.py 2>/logs/verifier/grade.log diff --git a/game_first_exam/tests/benchmarks/rocketleague/concede/run_harbor.py b/game_first_exam/tests/benchmarks/rocketleague/concede/run_harbor.py new file mode 100644 index 0000000..d823106 --- /dev/null +++ b/game_first_exam/tests/benchmarks/rocketleague/concede/run_harbor.py @@ -0,0 +1,33 @@ +import json +import shutil +import subprocess +import sys +import tempfile +from pathlib import Path + + +def main(): + root = Path.cwd() + prepare = root / "scripts/prepare_games.py" + if not prepare.is_file(): + raise SystemExit("Run this script from the Game Exam repository root.") + staging = root / "jobs/prepared" + staging.mkdir(parents=True, exist_ok=True) + run = Path(tempfile.mkdtemp(prefix="rocketleague-concede-", dir=staging)) + config = run / "control.json" + subprocess.run([sys.executable, str(prepare), "--suite", "rocketleague", "--output", str(config)], + check=True) + rows = json.loads(config.read_text())["tasks"] + if len(rows) != 1: + raise RuntimeError("Expected one Rocket League task.") + task = Path(rows[0]["path"]).resolve() + if not task.is_relative_to(run) or task.name != "rocketleague-first-goal-i01-standard": + raise RuntimeError("Expected a staged copy of Rocket League first goal.") + shutil.copyfile(Path(__file__).with_name("solve.py"), task / "solution/solve.py") + subprocess.run([sys.executable, str(root / "scripts/stamp_mtimes.py"), "--full", str(task)], check=True) + subprocess.run(["harbor", "run", "-c", str(config), "-a", "oracle", + "--jobs-dir", str(root / "jobs"), "-y"], check=True) + + +if __name__ == "__main__": + main() diff --git a/game_first_exam/tests/benchmarks/rocketleague/concede/solve.py b/game_first_exam/tests/benchmarks/rocketleague/concede/solve.py new file mode 100644 index 0000000..cac244c --- /dev/null +++ b/game_first_exam/tests/benchmarks/rocketleague/concede/solve.py @@ -0,0 +1,7 @@ +from game_client import GameClient + +game = GameClient() +state = game.observe() +while not state["done"]: + action = "boost_right" if state["step"] < 8 else "wait" + state = game.step(action, expected_step=state["step"]) diff --git a/game_first_exam/tests/benchmarks/rocketleague/exported.toml b/game_first_exam/tests/benchmarks/rocketleague/exported.toml new file mode 100644 index 0000000..4767e4a --- /dev/null +++ b/game_first_exam/tests/benchmarks/rocketleague/exported.toml @@ -0,0 +1,7 @@ +[protocols] +standard = ["game-standard/2.2"] + +[[tasks]] +name = "rocketleague-first-goal-i01-standard" +source_task = "GameWorld-25_01" +protocol = "game-standard/2.2" diff --git a/game_first_exam/tests/test_game_harbor.py b/game_first_exam/tests/test_game_harbor.py index e6e71f6..4707ea4 100644 --- a/game_first_exam/tests/test_game_harbor.py +++ b/game_first_exam/tests/test_game_harbor.py @@ -32,13 +32,13 @@ class GameSelection(unittest.TestCase): def test_game_only_default_and_all_selection_never_launches(self): for flags, expected in ((["--list", "--standard"], 30), - (["--all", "--standard", "--list"], 42)): + (["--all", "--standard", "--list"], 43)): with self.subTest(flags=flags), contextlib.redirect_stdout(io.StringIO()) as output, \ patch("efe.harbor") as launch, patch("efe.prepull") as pull: self.assertEqual(efe.run(flags), 0) names = output.getvalue().splitlines() self.assertEqual(len(names), expected) - self.assertTrue(all(name.startswith(("minigrid-", "crafter-", "textworld-", "babaisai-", "minihack-")) + self.assertTrue(all(name.startswith(("minigrid-", "crafter-", "textworld-", "babaisai-", "minihack-", "rocketleague-")) for name in names)) launch.assert_not_called() pull.assert_not_called() diff --git a/game_first_exam/tests/test_rocketleague.py b/game_first_exam/tests/test_rocketleague.py new file mode 100644 index 0000000..9352e54 --- /dev/null +++ b/game_first_exam/tests/test_rocketleague.py @@ -0,0 +1,22 @@ +import unittest +from pathlib import Path +from runpy import run_path + +rules = Path(__file__).resolve().parents[1] / "benchmarks/rocketleague/metric_rules.py" +validate = run_path(str(rules))["validate_metrics"] + + +class FirstGoalTests(unittest.TestCase): + def check_score(self, own, opponent, ended, won): + validate({"metrics": {"goals_for": own, "goals_against": opponent, "success": int(won)}, + "terminated": ended, "success": won, "return": float(won)}, {}) + + def test_scorelines(self): + self.check_score(1, 0, True, True) + self.check_score(0, 1, True, False) + self.check_score(0, 0, False, False) + + def test_inconsistent_records(self): + for record in [(1, 1, True, True), (0, 1, True, True), (0, 0, True, False)]: + with self.subTest(record=record), self.assertRaises(ValueError): + self.check_score(*record) diff --git a/scripts/task_conventions.py b/scripts/task_conventions.py index 36b7e5c..b8abaa6 100644 --- a/scripts/task_conventions.py +++ b/scripts/task_conventions.py @@ -73,6 +73,7 @@ # ci_checks/ci_scope.py --check holds its UNITS / FILES_IMAGE to it. A new benchmark adds one row here. BENCHMARK_TABLE = [ ("minihack-", "MiniHack", "minihack"), + ("rocketleague-", "GameWorld Rocket League 2D", "rocketleague"), ("babaisai-", "Baba Is AI", "babaisai"), ("crafter-", "Crafter", "crafter"), ("textworld-", "TextWorld", "textworld"), diff --git a/scripts/task_resources.toml b/scripts/task_resources.toml index f5e2106..0aa20b3 100644 --- a/scripts/task_resources.toml +++ b/scripts/task_resources.toml @@ -9,7 +9,7 @@ measured = "CPU-only initial integration; caps chosen conservatively, to be meas # Initial CPU-only game integration caps; measure before increasing concurrency. [[cap]] -match = "^(crafter|textworld|babaisai)-.*-standard$" +match = "^(crafter|textworld|babaisai|rocketleague)-.*-standard$" main = { cpus = 1, memory_gb = 1, pids = 256, disk_gb = 2 } sim = { cpus = 1, memory_gb = 1, pids = 128 } measured = "Initial integration caps; CPU only, fixed-model evaluation"