diff --git a/.github/workflows/games.yml b/.github/workflows/games.yml index ebee4f6..c3b06c9 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 firewater --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: firewater, control: firewater/missed_jump} + 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..f3f7fc3 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.firewater] +schema = "game_first_exam/benchmarks/firewater/instance_schema.py" diff --git a/configs/game_suites/firewater.toml b/configs/game_suites/firewater.toml new file mode 100644 index 0000000..3d88af5 --- /dev/null +++ b/configs/game_suites/firewater.toml @@ -0,0 +1,10 @@ +schema_version = "game-suite/2.1" +version = "1.0.0" +tier = "smoke" +name = "games-firewater-minimal-v1.0.0" +files_images = ["connection-files", "game-files", "firewater-files"] + +[[tasks]] +name = "firewater-forest-exit-i01-standard" +benchmark = "firewater" +family = "forest-exit" diff --git a/docs/demos/firewater/level-1-clear.mp4 b/docs/demos/firewater/level-1-clear.mp4 new file mode 100644 index 0000000..3464f3e Binary files /dev/null and b/docs/demos/firewater/level-1-clear.mp4 differ diff --git a/docs/demos/firewater/level-1-missed-jump.mp4 b/docs/demos/firewater/level-1-missed-jump.mp4 new file mode 100644 index 0000000..b05dae2 Binary files /dev/null and b/docs/demos/firewater/level-1-missed-jump.mp4 differ diff --git a/game_first_exam/benchmarks/firewater/adapter.py b/game_first_exam/benchmarks/firewater/adapter.py new file mode 100644 index 0000000..25d83cc --- /dev/null +++ b/game_first_exam/benchmarks/firewater/adapter.py @@ -0,0 +1,156 @@ +"""Forest Temple level one, scored by its native terminal outcome.""" +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": ("left",), "right": ("right",), + "jump_left": ("jump", "left"), "jump_right": ("jump", "right"), +} +KEYS = { + "fireboy": {"left": "ArrowLeft", "right": "ArrowRight", "jump": "ArrowUp"}, + "watergirl": {"left": "a", "right": "d", "jump": "w"}, +} +ORIGIN = "http://forest.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": 800, "height": 600}) + + 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 == "forest.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?level=1", wait_until="domcontentloaded") + for _ in range(160): + self.page.clock.run_for(250) + state = self.page.evaluate("() => window.gameAPI?.getState()") + if state and state["is_actionable"]: + board = state["game_state"] + if all(board["diamonds"][r]["total"] for r in KEYS) and board["level"] == 1: + self.state = state + break + else: + raise RuntimeError("GameWorld did not initialize forest level 1") + # Let the native opening animation settle before accepting the first action. + self.page.clock.run_for(4000) + self.state = self.page.evaluate("gameAPI.getState()") + # Count native updates. Phaser can render a frame without advancing the physics. + self.page.evaluate("""() => { + const game = window.__fbwg_game || window.Phaser.GAMES[0]; + window.forestTicks = 0; + game.plugins.add({postUpdate() { window.forestTicks++; }}); + }""") + 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": [f"{a}/{b}" for a in MOVES for b in MOVES]}, + "actions": "fireboy/watergirl, six native updates per paired move", + "goal": "Guide both characters into their matching exits on forest level one."} + + 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): + moves = action.split("/") + if len(moves) != 2 or any(move not in MOVES for move in moves): + raise ValueError("expected two role moves") + if self.state["terminal"]["isTerminal"]: + raise ValueError("episode already ended") + keys = [KEYS[role][direction] for role, move in zip(KEYS, moves) for direction in MOVES[move]] + for key in keys: + self.page.keyboard.down(key) + try: + target = self.page.evaluate("window.forestTicks") + 6 + self.page.clock.run_for(96) + for _ in range(16): + ticks = self.page.evaluate("window.forestTicks") + if ticks == target: + break + if ticks > target: + raise RuntimeError("native updates exceeded action interval") + if self.page.evaluate("gameAPI.getState().terminal.isTerminal"): + break + self.page.clock.run_for(16) + else: + raise RuntimeError("native game stopped advancing") + finally: + for key in reversed(keys): + self.page.keyboard.up(key) + self.steps += 1 + self.state = self.page.evaluate("gameAPI.getState()") + self.capture() + won = self.success() + return Transition(float(won), self.state["terminal"]["isTerminal"]) + + def counts(self): + gems = self.state["game_state"]["diamonds"] + return {role: gems[role]["collected"] for role in KEYS} + + def success(self): + terminal = self.state["terminal"] + return (self.state["game_state"]["level"] == 1 and terminal["isTerminal"] + and terminal["outcome"] == "success" and terminal["reason"] == "level_completed") + + def metrics(self): + return {**self.counts(), "success": int(self.success()), "level": self.state["game_state"]["level"], + "terminal_outcome": self.state["terminal"]["outcome"], + "terminal_reason": self.state["terminal"]["reason"]} + + def fingerprint(self): + board = self.state["game_state"] + positions = [] + for role in ("player", "watergirl"): + body = board.get(role) or {} + positions.append([round(body[axis] / 8) if body.get(axis) is not None else None + for axis in ("x", "y")]) + return state_hash({"level": board["level"], "positions": positions, "gems": self.counts(), + "steps": self.steps, "game_over": self.state["terminal"]["isTerminal"]}) + + def close(self): + self.stack.close() diff --git a/game_first_exam/benchmarks/firewater/instance_schema.py b/game_first_exam/benchmarks/firewater/instance_schema.py new file mode 100644 index 0000000..4c426dc --- /dev/null +++ b/game_first_exam/benchmarks/firewater/instance_schema.py @@ -0,0 +1,13 @@ +SCHEMA_VERSION = "1.0.0" +BENCHMARK = "firewater" +FIELDS = {"engine_commit"} +METRICS = {"success"} +PROFILES = {"native-rgb-v1"} +REDUCERS = {("family_macro", "1.0.0")} + + +def validate(value): + if value["engine_commit"] != "e5ddb16df85b91a1d17bb0577621cc7c5e65d738": + raise ValueError("unknown GameWorld-Games version") + if (value["env_id"], value["family"], value["max_steps"]) != ("forest-temple-level-1", "forest-exit", 800): + raise ValueError("unknown GameWorld task configuration") diff --git a/game_first_exam/benchmarks/firewater/metric_rules.py b/game_first_exam/benchmarks/firewater/metric_rules.py new file mode 100644 index 0000000..cbbd2b4 --- /dev/null +++ b/game_first_exam/benchmarks/firewater/metric_rules.py @@ -0,0 +1,19 @@ +"""Consistency checks for the terminal result reported by the native forest level.""" + + +def validate_metrics(final, instance): + metrics = final["metrics"] + if metrics["level"] != 1: + raise ValueError("unexpected forest level") + for role in ("fireboy", "watergirl"): + if type(metrics[role]) is not int or metrics[role] < 0: + raise ValueError(f"invalid diamond count for {role}") + + terminal = (metrics["terminal_outcome"], metrics["terminal_reason"]) + valid_events = {(None, None), ("success", "level_completed"), + ("fail", "level_failed"), ("fail", "level_ended")} + if terminal not in valid_events or final["terminated"] != (terminal != (None, None)): + raise ValueError("inconsistent native terminal event") + won = terminal == ("success", "level_completed") + if final["success"] != won or final["return"] != float(won) or metrics["success"] != int(won): + raise ValueError("reward disagrees with native level completion") diff --git a/game_first_exam/benchmarks/firewater/requirements.txt b/game_first_exam/benchmarks/firewater/requirements.txt new file mode 100644 index 0000000..70da3b9 --- /dev/null +++ b/game_first_exam/benchmarks/firewater/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/firewater-files/FILES.json b/game_first_exam/images/firewater-files/FILES.json new file mode 100644 index 0000000..1b2bf11 --- /dev/null +++ b/game_first_exam/images/firewater-files/FILES.json @@ -0,0 +1,10 @@ +{ + "image": "ghcr.io/mll-lab-nu/efe:firewater-files-0.1.0@sha256:ab62600ad87d0847d601c5bce3be99243b6cd1d659234af944efded40395fa7a", + "source": "game_first_exam/benchmarks/firewater", + "files": { + "instance_schema.py": "0432b1c48b4f9ecd9839cfa85aa231e70c294b92ac2660ebf088fb11af5c7579", + "requirements.txt": "f7b63cd5e9d2d806613a620bb7340f27ce6735ba76c9d5a08f77d48e527d4733", + "adapter.py": "2834b4346b8c958ea21fb8e8768c9c9e1a9f7a20dbc6a13cfc06c0051d5aa0c5", + "metric_rules.py": "358a3350d3fc17a980f8d136789477ffbd01a0eab566188d19afd691d407fbd7" + } +} diff --git a/game_first_exam/images/firewater-files/README.md b/game_first_exam/images/firewater-files/README.md new file mode 100644 index 0000000..e783a73 --- /dev/null +++ b/game_first_exam/images/firewater-files/README.md @@ -0,0 +1,3 @@ +# Firewater adapter + +Pinned evaluator and simulator adapter for the native Forest Temple level-one exit. Game assets are fetched separately during the simulator build. diff --git a/game_first_exam/images/firewater-files/VERSION b/game_first_exam/images/firewater-files/VERSION new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/game_first_exam/images/firewater-files/VERSION @@ -0,0 +1 @@ +0.1.0 diff --git a/game_first_exam/tasks/firewater/README.md b/game_first_exam/tasks/firewater/README.md new file mode 100644 index 0000000..51c5f72 --- /dev/null +++ b/game_first_exam/tasks/firewater/README.md @@ -0,0 +1,33 @@ +# Fireboy and Watergirl in the Forest Temple + +This Game Exam task uses GameWorld's original Forest Temple level one. GameWorld 12_01 and 12_02 specify diamond targets. This variant runs all the way to the native successful exit event. Both characters must reach their matching doors. The game reports the diamonds collected as secondary metrics. + +Run from the repository root with Docker Desktop running and the project Harbor installation on PATH. + +```sh +harbor run --game-suite firewater --standard -a oracle +``` + +An action advances both roles by six native game updates with the browser clock paused between decisions. The reference solution sends paired actions through GameClient. The verifier checks the native terminal event. A completed episode produces the standard Game Exam replay and final verdict. + +- [Pinned upstream task](https://github.com/gameworld-project/GameWorld/blob/84f624bd1e120d30aeebf2eb42a39410e24d3bd4/catalog/tasks/12_fireboy-and-watergirl/12_01.yaml) +- [Pinned game and rights notice](https://github.com/gameworld-project/GameWorld-Games/blob/e5ddb16df85b91a1d17bb0577621cc7c5e65d738/benchmark/12_fireboy-and-watergirl/RIGHTS.md) + +The simulator build retrieves the pinned game from upstream. The game assets are downloaded during the simulator build. Oslo Albet retains the game's rights. + +## Level one demos and results + +| Browser gameplay | Native outcome | Paired moves | Harbor score | +| --- | --- | ---: | ---: | +| [Both characters reach their exits](../../../docs/demos/firewater/level-1-clear.mp4) | `level_completed` | 474 | 1 | +| [Watergirl misses the first lava jump](../../../docs/demos/firewater/level-1-missed-jump.mp4) | `level_failed` | 38 | 0 | + +Both Harbor runs returned valid results and zero environment errors. The success run collected all three red and four blue diamonds. The negative control delays Watergirl's first jump while Fireboy follows the reference opening. The clips were recorded separately in the browser. The Harbor recorder stopped before writing a playable MP4. + +To reproduce the negative control from the repository root: + +```sh +python game_first_exam/tests/benchmarks/firewater/missed_jump/run_harbor.py +``` + +The control uses a staged task copy with the offline rewarded-ad prompt disabled so the native Game Over menu opens. The agent submits paired moves through the same public client, and the verifier grades the native terminal event. diff --git a/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/DIGEST b/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/DIGEST new file mode 100644 index 0000000..f0bb448 --- /dev/null +++ b/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/DIGEST @@ -0,0 +1 @@ +sha256:0593140315afc1ec721b17277cace5a38d03f96b7089de05d6e90c9456b148d7 diff --git a/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/README.md b/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/README.md new file mode 100644 index 0000000..ff6fc5a --- /dev/null +++ b/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/README.md @@ -0,0 +1,35 @@ +# firewater-forest-exit-i01-standard + +| | | +|---|---| +| Benchmark | GameWorld Forest Temple | +| Mode | standard (`game-standard/2.2`) | +| Twin | — (none: GameWorld Forest Temple has no privileged mode, PROTOCOL §2) | +| Simulator / robot | `firewater` / `game-agent` | +| Family / instance | `forest-exit` / seed 0 | +| 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 +Bring Fireboy and Watergirl to their matching doors in the original Forest Temple level one. + +## Difficulty +Cross three pools and climb the temple. The two players take turns standing on pressure plates to move the purple lift. Push the crate to reach the final ledge. + +## Reference solution +The oracle plays a recorded sequence of paired keyboard movements through the public game client. Actions are grouped by room feature in solution/route.json. + +## Verification +The isolated verifier checks the native terminal event and level number. Death and an unfinished episode earn zero even if every diamond was collected. + +## 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/firewater/firewater-forest-exit-i01-standard/environment/Dockerfile b/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/environment/Dockerfile new file mode 100644 index 0000000..10dcc84 --- /dev/null +++ b/game_first_exam/tasks/firewater/firewater-forest-exit-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/firewater/firewater-forest-exit-i01-standard/environment/docker-compose.yaml b/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/environment/docker-compose.yaml new file mode 100644 index 0000000..7fa17b4 --- /dev/null +++ b/game_first_exam/tasks/firewater/firewater-forest-exit-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/firewater/firewater-forest-exit-i01-standard/environment/rcb_monitor/limits.json b/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/environment/rcb_monitor/limits.json new file mode 100644 index 0000000..e5550a7 --- /dev/null +++ b/game_first_exam/tasks/firewater/firewater-forest-exit-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": "firewater-forest-exit-i01-standard", + "tick_sec": 5 +} diff --git a/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/environment/sim/Dockerfile b/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/environment/sim/Dockerfile new file mode 100644 index 0000000..06ac84a --- /dev/null +++ b/game_first_exam/tasks/firewater/firewater-forest-exit-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:firewater-files-0.1.0@sha256:ab62600ad87d0847d601c5bce3be99243b6cd1d659234af944efded40395fa7a /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:firewater-files-0.1.0@sha256:ab62600ad87d0847d601c5bce3be99243b6cd1d659234af944efded40395fa7a /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/12_fireboy-and-watergirl && git fetch --depth=1 --filter=blob:none origin e5ddb16df85b91a1d17bb0577621cc7c5e65d738 && git checkout --detach FETCH_HEAD && mv benchmark/12_fireboy-and-watergirl /srv/game && rm -rf /tmp/upstream +COPY --from=ghcr.io/mll-lab-nu/efe:firewater-files-0.1.0@sha256:ab62600ad87d0847d601c5bce3be99243b6cd1d659234af944efded40395fa7a /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/firewater/firewater-forest-exit-i01-standard/environment/sim/instance.json b/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/environment/sim/instance.json new file mode 100644 index 0000000..3c37069 --- /dev/null +++ b/game_first_exam/tasks/firewater/firewater-forest-exit-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": "firewater", + "env_id": "forest-temple-level-1", + "family": "forest-exit", + "seed": 0, + "max_steps": 800, + "engine_commit": "e5ddb16df85b91a1d17bb0577621cc7c5e65d738", + "initial_state_sha256": "1054cb930c7ffd53a3563eda2e1240a6cd8eb020aff34346ded18404e2af87c8", + "observation_profile": "native-rgb-v1", + "metric_spec": { + "primary": "success", + "reducer": "family_macro", + "reducer_version": "1.0.0", + "success_label": "level_completed" + } +} diff --git a/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/instruction.md b/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/instruction.md new file mode 100644 index 0000000..952e5a1 --- /dev/null +++ b/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/instruction.md @@ -0,0 +1,31 @@ +# Forest Temple · Level one + +Guide Fireboy and Watergirl into their matching exit doors in the upper-right corner. The native level-completion event earns one point. Death, a timeout and reaching the action limit earn zero. You have one episode of up to 800 paired actions. + +Each action is a pair of moves separated by a slash, Fireboy first. Choose wait, left, right, jump_left or jump_right for each role. For example, wait/jump_left holds Fireboy still while Watergirl jumps left. Inputs are held for six native game updates (about 0.1 seconds). The world pauses between actions. Read the RGB frame with GameClient.save_image(). + +Fireboy can cross red lava, Watergirl can cross blue water, and green liquid endangers both. The route includes a lever, two pressure plates, lifts and a movable crate. Diamonds are reported separately in the final metrics. + +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/firewater/firewater-forest-exit-i01-standard/solution/route.json b/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/solution/route.json new file mode 100644 index 0000000..b6a1810 --- /dev/null +++ b/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/solution/route.json @@ -0,0 +1,17 @@ +[ + {"section": "Cross the pools", "moves": [[18, "right/right"], [8, "right/jump_right"], [4, "right/right"], [6, "jump_right/right"], [3, "right/right"], [2, "jump_right/right"], [5, "jump_right/jump_right"], [1, "wait/jump_right"]]}, + {"section": "Climb the right shelf", "moves": [[9, "wait/wait"], [3, "left/left"], [6, "jump_left/jump_left"]]}, + {"section": "Jump over the green pool", "moves": [[3, "left/left"], [6, "jump_left/jump_left"], [22, "left/left"]]}, + {"section": "Switch the lever", "moves": [[10, "left/left"]]}, + {"section": "Board the yellow lift", "moves": [[1, "wait/wait"], [13, "jump_left/jump_left"], [3, "wait/wait"], [6, "jump_left/jump_left"], [13, "wait/wait"]]}, + {"section": "Climb to the first plate", "moves": [[1, "wait/wait"], [7, "jump_right/jump_right"], [1, "right/right"]]}, + {"section": "Watergirl boards the purple lift", "moves": [[5, "right/right"], [27, "wait/right"], [5, "wait/jump_right"]]}, + {"section": "Raise Watergirl", "moves": [[1, "wait/wait"], [18, "right/wait"]]}, + {"section": "Change pressure plates", "moves": [[1, "right/wait"], [6, "right/jump_left"], [1, "wait/jump_left"], [4, "wait/left"]]}, + {"section": "Fireboy boards the lift", "moves": [[1, "wait/left"], [16, "wait/wait"], [7, "right/wait"], [3, "wait/wait"], [5, "jump_right/wait"]]}, + {"section": "Raise Fireboy", "moves": [[1, "wait/wait"], [3, "wait/left"], [8, "wait/jump_left"], [1, "wait/left"], [6, "wait/wait"]]}, + {"section": "Push the crate left", "moves": [[1, "wait/wait"], [5, "wait/left"], [1, "wait/wait"], [2, "wait/left"], [1, "wait/wait"], [5, "wait/left"], [1, "wait/wait"], [6, "wait/left"], [1, "wait/wait"], [7, "wait/left"], [10, "wait/right"], [11, "wait/left"], [7, "jump_left/left"], [7, "left/left"], [3, "jump_left/left"], [1, "wait/left"], [3, "jump_left/left"], [24, "left/left"]]}, + {"section": "Climb the crate", "moves": [[1, "left/left"], [17, "jump_left/jump_left"], [3, "wait/wait"], [6, "jump_left/jump_left"]]}, + {"section": "Jump to the top floor", "moves": [[9, "wait/wait"], [6, "right/right"], [12, "jump_right/jump_right"]]}, + {"section": "Enter both matching exits", "moves": [[26, "right/right"], [1, "wait/right"], [3, "left/right"], [1, "wait/wait"], [3, "wait/left"], [20, "wait/wait"]]} +] diff --git a/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/solution/solve.py b/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/solution/solve.py new file mode 100644 index 0000000..9283ebd --- /dev/null +++ b/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/solution/solve.py @@ -0,0 +1,25 @@ +"""Replay the paired inputs from a successful run of the frozen first level.""" +import json +from pathlib import Path + +from game_client import GameClient + + +def main(): + game = GameClient() + observation = game.observe() + route = json.loads(Path(__file__).with_name("route.json").read_text()) + for section in route: + for count, action in section["moves"]: + for _ in range(count): + if observation["done"]: + print(f"Native episode ended after {observation['step']} paired actions.") + return + observation = game.step(action, expected_step=observation["step"]) + if not observation["done"]: + raise RuntimeError("Reference inputs ended before the native game finished.") + print(f"Native episode ended after {observation['step']} paired actions.") + + +if __name__ == "__main__": + main() diff --git a/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/solution/solve.sh b/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/solution/solve.sh new file mode 100755 index 0000000..a856bf7 --- /dev/null +++ b/game_first_exam/tasks/firewater/firewater-forest-exit-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/firewater/firewater-forest-exit-i01-standard/task.toml b/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/task.toml new file mode 100644 index 0000000..8fffac7 --- /dev/null +++ b/game_first_exam/tasks/firewater/firewater-forest-exit-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/firewater-forest-exit-i01-standard" +description = "Complete forest level one by guiding Fireboy and Watergirl into their matching doors." +keywords = ["game", "firewater", "puzzle", "cooperative-platformer", "standard-mode"] + +[metadata] +task_type = "trajectory" +simulator = "firewater" +robot = "game-agent" +family = "forest-exit" +dynamics = "static" +protocol = "game-standard/2.2" +oracle = "full" +instance_seed = 0 +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/firewater/firewater-forest-exit-i01-standard/tests/Dockerfile b/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/tests/Dockerfile new file mode 100644 index 0000000..e7419ac --- /dev/null +++ b/game_first_exam/tasks/firewater/firewater-forest-exit-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:firewater-files-0.1.0@sha256:ab62600ad87d0847d601c5bce3be99243b6cd1d659234af944efded40395fa7a /instance_schema.py /tests/instance_schema.py +COPY --from=ghcr.io/mll-lab-nu/efe:firewater-files-0.1.0@sha256:ab62600ad87d0847d601c5bce3be99243b6cd1d659234af944efded40395fa7a /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/firewater/firewater-forest-exit-i01-standard/tests/instance.json b/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/tests/instance.json new file mode 100644 index 0000000..3c37069 --- /dev/null +++ b/game_first_exam/tasks/firewater/firewater-forest-exit-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": "firewater", + "env_id": "forest-temple-level-1", + "family": "forest-exit", + "seed": 0, + "max_steps": 800, + "engine_commit": "e5ddb16df85b91a1d17bb0577621cc7c5e65d738", + "initial_state_sha256": "1054cb930c7ffd53a3563eda2e1240a6cd8eb020aff34346ded18404e2af87c8", + "observation_profile": "native-rgb-v1", + "metric_spec": { + "primary": "success", + "reducer": "family_macro", + "reducer_version": "1.0.0", + "success_label": "level_completed" + } +} diff --git a/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/tests/rcb_limits.json b/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/tests/rcb_limits.json new file mode 100644 index 0000000..e5550a7 --- /dev/null +++ b/game_first_exam/tasks/firewater/firewater-forest-exit-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": "firewater-forest-exit-i01-standard", + "tick_sec": 5 +} diff --git a/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/tests/test.sh b/game_first_exam/tasks/firewater/firewater-forest-exit-i01-standard/tests/test.sh new file mode 100755 index 0000000..0cf878a --- /dev/null +++ b/game_first_exam/tasks/firewater/firewater-forest-exit-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/firewater/exported.toml b/game_first_exam/tests/benchmarks/firewater/exported.toml new file mode 100644 index 0000000..a184591 --- /dev/null +++ b/game_first_exam/tests/benchmarks/firewater/exported.toml @@ -0,0 +1,7 @@ +[protocols] +standard = ["game-standard/2.2"] + +[[tasks]] +name = "firewater-forest-exit-i01-standard" +source_task = "GameWorld-Forest-Temple-Level-1-Native-Exit" +protocol = "game-standard/2.2" diff --git a/game_first_exam/tests/benchmarks/firewater/missed_jump/run_harbor.py b/game_first_exam/tests/benchmarks/firewater/missed_jump/run_harbor.py new file mode 100644 index 0000000..fe1aba5 --- /dev/null +++ b/game_first_exam/tests/benchmarks/firewater/missed_jump/run_harbor.py @@ -0,0 +1,49 @@ +"""Run the late-jump inputs in an isolated copy of the standard Harbor task.""" +import json +import shutil +import subprocess +import sys +import tempfile +from pathlib import Path + + +def stage_control(task, adapter): + shutil.copyfile(Path(__file__).with_name("solve.py"), task / "solution/solve.py") + sim = task / "environment/sim" + # The offline game has no rewarded-ad provider. Hide that menu item so the + # native Game Over screen can finish opening after Watergirl dies. + source = adapter.read_text() + anchor = ' self.page.clock.run_for(4000)' + if source.count(anchor) != 1: + raise RuntimeError("Check the initialization point in the current Forest Temple adapter.") + settings = ' self.page.evaluate("h5branding.Branding.analyticsEnabled = false")\n' + (sim / "offline_adapter.py").write_text(source.replace(anchor, settings + anchor)) + with (sim / "Dockerfile").open("a") as stream: + stream.write("\nCOPY offline_adapter.py /srv/adapter.py\n") + + +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="firewater-missed-jump-", dir=staging)) + config = run / "control.json" + subprocess.run([sys.executable, str(prepare), "--suite", "firewater", "--output", str(config)], + check=True) + rows = json.loads(config.read_text())["tasks"] + if len(rows) != 1: + raise RuntimeError("Expected one Forest Temple task.") + task = Path(rows[0]["path"]).resolve() + if not task.is_relative_to(run) or task.name != "firewater-forest-exit-i01-standard": + raise RuntimeError("Expected a staged copy of Forest Temple level one.") + stage_control(task, root / "game_first_exam/benchmarks/firewater/adapter.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/firewater/missed_jump/solve.py b/game_first_exam/tests/benchmarks/firewater/missed_jump/solve.py new file mode 100644 index 0000000..77b0093 --- /dev/null +++ b/game_first_exam/tests/benchmarks/firewater/missed_jump/solve.py @@ -0,0 +1,25 @@ +"""Replay the opening of level one with Watergirl's first jump six inputs late.""" +from game_client import GameClient + + +def main(): + game = GameClient() + state = game.observe() + # The winning route starts holding Watergirl's jump after input 18. + # Keep moving for six more inputs before trying to jump. + for count, action in ((24, "right/right"), (2, "right/jump_right"), (4, "right/right"), + (6, "jump_right/right"), (3, "right/right"), (2, "jump_right/right"), + (5, "jump_right/jump_right"), (1, "wait/jump_right"), + (9, "wait/wait"), (3, "left/left"), (6, "jump_left/jump_left"), + (100, "wait/wait")): + for _ in range(count): + if state["done"]: + print(f"Native episode ended at step {state['step']}.") + return + state = game.step(action, expected_step=state["step"]) + if not state["done"]: + raise RuntimeError("Expected the missed jump to end the episode.") + + +if __name__ == "__main__": + main() diff --git a/game_first_exam/tests/test_firewater.py b/game_first_exam/tests/test_firewater.py new file mode 100644 index 0000000..51fec04 --- /dev/null +++ b/game_first_exam/tests/test_firewater.py @@ -0,0 +1,38 @@ +"""Regression cases for the native Forest Temple exit objective.""" +import importlib.util +import unittest +from pathlib import Path + +source = Path(__file__).resolve().parents[1] / "benchmarks/firewater/metric_rules.py" +spec = importlib.util.spec_from_file_location("firewater_metrics", source) +rules = importlib.util.module_from_spec(spec) +spec.loader.exec_module(rules) + + +def verdict(outcome=None, reason=None, *, red=0, blue=0): + won = outcome == "success" + return {"terminated": outcome is not None, "success": won, "return": float(won), + "metrics": {"level": 1, "fireboy": red, "watergirl": blue, + "terminal_outcome": outcome, "terminal_reason": reason, + "success": int(won)}} + + +class ForestExitTests(unittest.TestCase): + def test_native_completion(self): + for red, blue in ((3, 4), (0, 0)): + rules.validate_metrics(verdict("success", "level_completed", red=red, blue=blue), {}) + + def test_diamonds_without_exit_do_not_win(self): + for outcome, reason in ((None, None), ("fail", "level_failed"), ("fail", "level_ended")): + final = verdict(outcome, reason, red=3, blue=4) + rules.validate_metrics(final, {}) + final.update(success=True, **{"return": 1.0}) + with self.assertRaises(ValueError): + rules.validate_metrics(final, {}) + + def test_disagrees_with_native_event(self): + for key, value in (("level", 2), ("terminal_reason", None), ("watergirl", -1)): + final = verdict("success", "level_completed") + final["metrics"][key] = value + with self.assertRaises(ValueError): + rules.validate_metrics(final, {}) diff --git a/game_first_exam/tests/test_game_harbor.py b/game_first_exam/tests/test_game_harbor.py index e6e71f6..98fa556 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-", "firewater-")) for name in names)) launch.assert_not_called() pull.assert_not_called() diff --git a/scripts/task_conventions.py b/scripts/task_conventions.py index 36b7e5c..509bb24 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"), + ("firewater-", "GameWorld Forest Temple", "firewater"), ("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..6eb6729 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|firewater)-.*-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"