Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions .github/workflows/games.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 pacman --standard --list
- run: python game_first_exam/tests/test_game_harbor.py
fresh-clone-smoke:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -77,8 +78,43 @@ jobs:
name: fresh-clone-room-evidence
path: jobs/
retention-days: 7
pacman-smoke:
runs-on: ubuntu-latest
timeout-minutes: 35
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: Assemble the pinned Pac-Man files image
run: python scripts/files_image.py build pacman-files
- name: Run the 600-point reference
run: |
harbor run --game-suite pacman --standard -c configs/harbor/oracle.json \
--jobs-dir "$PWD/jobs" --job-name pacman-clear -y
python ci_checks/check-pacman-result.py jobs/pacman-clear 1
- name: Run the ghost-collision control
run: |
python game_first_exam/tests/benchmarks/pacman/ghost_collision/run_harbor.py
python ci_checks/check-pacman-result.py jobs/pacman-failure-control 0
- uses: actions/upload-artifact@v4
if: always()
with:
name: pacman-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, pacman-smoke]
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
Expand All @@ -87,4 +123,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
PACMAN_SMOKE: ${{ needs.pacman-smoke.result }}
run: test "$STATIC" = success && test "$ADAPTERS" = success && test "$HARBOR" = success && test "$SMOKE" = success && test "$PACMAN_SMOKE" = success
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Game Exam 基于 [Embodied First Exam](https://github.com/mll-lab-nu/embodied-fi

## 已接入的游戏

当前共有 **5 个 benchmark、42 个 standard 任务配置,另外有 1 个 privileged 和 1 个 realtime 配置,共 44 个任务目录**。同一原生任务的不同模式单独计数。
当前共有 **6 个 benchmark、43 个 standard 任务配置,另外有 1 个 privileged 和 1 个 realtime 配置,共 45 个任务目录**。同一原生任务的不同模式单独计数。

| Benchmark | standard | 其他模式 | 主要内容 | 说明 |
|---|---:|---|---|---|
Expand All @@ -33,6 +33,7 @@ Game Exam 基于 [Embodied First Exam](https://github.com/mll-lab-nu/embodied-fi
| TextWorld | 9 | — | 文字探索、寻宝、烹饪 | 冻结 `.z8` 游戏,通过原生引擎执行 |
| Baba Is AI | 2 | — | 移动文字、改变规则、解谜 | 基础关卡与复合关卡的最小 smoke 验证 |
| MiniHack | 10 | 1 privileged | Room、River、导航、战斗、Quest、Boxoban | 原生 MiniHack/NLE 环境;Room 另有 privileged 版本 |
| Pac-Man | 1 | — | 浏览器吃豆与躲避幽灵 | GameWorld 固定 600 分目标;通关 1.0、死亡对照 0.0,含录像 |

套件由 [configs/game_suites/](configs/game_suites/) 定义,可以重叠,数量不能直接相加:

Expand All @@ -45,8 +46,9 @@ Game Exam 基于 [Embodied First Exam](https://github.com/mll-lab-nu/embodied-fi
| `textworld` | 9 | TextWorld 当前实例 |
| `babaisai` | 2 | Baba Is AI smoke |
| `minihack` | 3 | Room/River standard + Room privileged |
| `pacman` | 1 | GameWorld Pac-Man 600 分;本地适配验证中 |
| `minihack-balrog` | 8 | 参考 BALROG 选取的原生 MiniHack 任务 |
| `all` | 44 | 所有套件去重后的任务;汇总时应选择一种模式 |
| `all` | 45 | 所有套件去重后的任务;汇总时应选择一种模式 |

`minihack-balrog` 包含 MazeWalk 9×9、MazeWalk 15×15、Corridor R3、CorridorBattle Dark、Quest Easy、Quest Medium、Boxoban Medium、Boxoban Hard。**使用相同原生环境名称不意味着与 BALROG 的 LLM 输入、prompt、agent、seed 和预算完全相同**,成绩不能直接当作 BALROG 排行榜成绩。

Expand Down Expand Up @@ -153,7 +155,7 @@ harbor run --game-suite minihack --standard --family room \

| 模式 | 执行方式 | 当前覆盖 |
|---|---|---|
| `standard` | agent 通过客户端操作可信模拟器,按动作推进;对 live episode 评分 | 5 个游戏、42 个配置 |
| `standard` | agent 通过客户端操作可信模拟器,按动作推进;对 live episode 评分 | 6 个游戏、43 个配置 |
| `privileged` | agent 可本地探索和规划;最终动作序列由独立 verifier 重新执行 | MiniHack Room |
| `realtime` | 首次有效动作计划启动固定 tick;程序与模型思考期间游戏继续推进 | Crafter survival i01 |

Expand Down
47 changes: 47 additions & 0 deletions ci_checks/check-pacman-result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python3
"""Validate a Pac-Man Harbor reference or failure job from trusted artifacts."""

import json
import sys
from pathlib import Path


def check(job: Path, expected_success: int):
trials = sorted(job.glob("*/result.json"))
if len(trials) != 1:
raise ValueError(f"Expected one Pac-Man trial in {job}, got {len(trials)}")

result = json.loads(trials[0].read_text())
if result.get("exception_info") is not None:
raise ValueError(f"Harbor raised an exception: {result['exception_info']}")
if result.get("agent_info", {}).get("name") != "oracle":
raise ValueError("Reference run must use the oracle agent")
if result["task_name"].rsplit("/", 1)[-1] != "pacman-600-i01-standard":
raise ValueError("Wrong Pac-Man task")

trial = trials[0].parent
reward = json.loads((trial / "verifier/reward.json").read_text())
final = json.loads((trial / "artifacts/data/final.json").read_text())
for key in ("infra_error", "sim_error", "environment_error"):
if reward.get(key) != 0:
raise ValueError(f"{key}: {reward.get(key)}")
if (reward.get("result_valid") != 1 or reward.get("success") != expected_success
or reward.get("primary_score") != expected_success or reward.get("steps", 0) <= 0):
raise ValueError(f"Unexpected verifier outcome: {reward}")

metrics = final["metrics"]
if final.get("initial_state_sha256") != "628cb4ead38e34e34a34f78fa4481f2a0ccf8e9139acfae69d79dc997e90e36b":
raise ValueError("Pac-Man opening changed")
if final.get("steps") != reward["steps"] or final.get("success") != bool(expected_success):
raise ValueError("Native result disagrees with verifier")
if expected_success:
if metrics["score"] < 600 or metrics["deaths"] != 0:
raise ValueError(f"Reference did not clear 600 points: {metrics}")
elif metrics["score"] >= 600 or metrics["deaths"] < 1:
raise ValueError(f"Control did not end in game over below 600: {metrics}")
print(f"{job}: valid Pac-Man {'clear' if expected_success else 'failure'}, "
f"score={metrics['score']}, steps={reward['steps']}")


if __name__ == "__main__":
check(Path(sys.argv[1]), int(sys.argv[2]))
3 changes: 3 additions & 0 deletions configs/game_benchmarks.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.pacman]
schema = "game_first_exam/benchmarks/pacman/instance_schema.py"
10 changes: 10 additions & 0 deletions configs/game_suites/pacman.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
schema_version = "game-suite/2.1"
version = "1.0.0"
tier = "smoke"
name = "games-pacman-minimal-v1.0.0"
files_images = ["connection-files", "game-files", "pacman-files"]

[[tasks]]
name = "pacman-600-i01-standard"
benchmark = "pacman"
family = "score-600"
Binary file added docs/demos/pacman/600-point-clear.mp4
Binary file not shown.
Binary file added docs/demos/pacman/explained-clear.mp4
Binary file not shown.
Binary file added docs/demos/pacman/explained-failure.mp4
Binary file not shown.
Binary file added docs/demos/pacman/ghost-collision.mp4
Binary file not shown.
7 changes: 7 additions & 0 deletions game_first_exam/benchmarks/pacman/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Pac-Man: 600 points

GameWorld's pinned `23_pacman` browser snapshot. An agent controls Pac-Man with four arrow keys and RGB screenshots. The native score must reach 600 before the native game-over screen. Ghost movement and collisions stay native; a game over terminates with reward zero. The adapter freezes browser time between 500 ms input intervals. The score is read from the native GameWorld API, not OCR or agent output.

This is an integration task based on the first GameWorld score threshold, not a claim of reproducing the GameWorld leaderboard. The source is https://github.com/gameworld-project/GameWorld-Games/tree/e5ddb16df85b91a1d17bb0577621cc7c5e65d738/benchmark/23_pacman ; see `RIGHTS.md` in that directory.

The 24-action reference route reached 600 points on the unmodified pinned browser game at seed 42. A stationary control ended in native game over at 120 points. Both browser runs were recorded. The `pacman-files` OCI digest was calculated locally but has not yet been published to GHCR. The Harbor oracle scored 1.0 in 24 actions with 600 points and zero deaths; the 78-action ghost-collision control scored 0.0 with 120 points and one game over. Both verifier records were valid and reported zero environment errors (2026-11-24).
111 changes: 111 additions & 0 deletions game_first_exam/benchmarks/pacman/adapter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
"""Play the pinned GameWorld Pac-Man snapshot with paused browser time."""

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

KEYS = {"wait": None, "up": "ArrowUp", "down": "ArrowDown", "left": "ArrowLeft", "right": "ArrowRight"}
ORIGIN = "http://pacman.test"
TARGET_SCORE = 600


class Adapter:
def __init__(self, instance, assets=None):
self.resources = ExitStack()
try:
self.start((Path(assets) / "game").resolve())
except BaseException:
self.close()
raise

def start(self, root):
driver = self.resources.enter_context(sync_playwright())
browser = driver.chromium.launch(args=["--mute-audio"])
self.resources.callback(browser.close)
self.page = browser.new_page(viewport={"width": 854, "height": 480})

def serve(route):
url = urlsplit(route.request.url)
path = (root / unquote(url.path).lstrip("/")).resolve()
if url.netloc == "pacman.test" and path.is_relative_to(root) and path.is_file():
route.fulfill(path=path)
else:
route.abort()

self.page.route("**/*", serve)
self.cdp = self.page.context.new_cdp_session(self.page)
opening = datetime(2025, 1, 1, tzinfo=timezone.utc)
self.page.clock.install(time=opening)
self.page.clock.pause_at(opening + timedelta(seconds=1))
self.page.goto(ORIGIN + "/index.html", wait_until="domcontentloaded")
for _ in range(1000):
self.page.clock.run_for(50)
self.state = self.page.evaluate("() => window.gameAPI?.getState()")
if self.state and self.state["status"] == "playing":
break
else:
raise RuntimeError(f"Pac-Man did not start: {self.state}")
if self.state["game_state"]["score"] is None:
raise RuntimeError("Native score unavailable at start")
self.capture()

def spec(self):
return {"adapter_version": "1.0.0", "capabilities": Capabilities(True, "enum").to_dict(),
"action_schema": {"type": "string", "enum": list(KEYS)},
"goal": "Earn at least 600 points before native game over."}

def success(self):
return self.state["game_state"]["score"] >= TARGET_SCORE

def done(self):
return self.success() or self.state["terminal"]["isTerminal"]

def step(self, action):
if self.done() or action not in KEYS:
raise ValueError("Expected a legal action during a live game")
key = KEYS[action]
if key:
self.page.keyboard.down(key)
try:
# Keep native timers and collisions moving for half a second.
for _ in range(10):
self.page.clock.run_for(50)
self.state = self.page.evaluate("gameAPI.getState()")
if self.done():
break
finally:
if key:
self.page.keyboard.up(key)
self.capture()
return Transition(float(self.success()), self.done())

def metrics(self):
return {"score": self.state["game_state"]["score"],
"deaths": self.state["metrics"]["deaths"], "success": int(self.success())}

def fingerprint(self):
return state_hash({"score": self.state["game_state"]["score"]})

def capture(self):
data = self.cdp.send("Page.captureScreenshot", {"format": "png"})["data"]
with Image.open(BytesIO(b64decode(data))) as image:
self.rgb = np.array(image.convert("RGB"))

def observe(self):
return {"image_png_base64": png(self.rgb)}

def frame(self):
return self.rgb

def close(self):
self.resources.close()
13 changes: 13 additions & 0 deletions game_first_exam/benchmarks/pacman/instance_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
SCHEMA_VERSION = "1.0.0"
BENCHMARK = "pacman"
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"]) != ("pacman", "score-600", 500):
raise ValueError("unknown Pac-Man task configuration")
14 changes: 14 additions & 0 deletions game_first_exam/benchmarks/pacman/metric_rules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def validate_metrics(final, instance):
metrics = final["metrics"]
score, deaths, success = (metrics[k] for k in ("score", "deaths", "success"))
if type(score) is not int or score < 0:
raise ValueError("Invalid native score")
if type(deaths) is not int or deaths < 0:
raise ValueError("Invalid native death count")
if type(success) is not int or success not in (0, 1) or success != int(score >= 600):
raise ValueError("Score and goal disagree")
won = bool(success)
if final["terminated"] != bool(won or deaths):
raise ValueError("Terminal flag disagrees with native result")
if final["success"] != won or final["return"] != float(won):
raise ValueError("Reward disagrees with native result")
5 changes: 5 additions & 0 deletions game_first_exam/benchmarks/pacman/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions game_first_exam/images/pacman-files/FILES.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"source": "game_first_exam/benchmarks/pacman",
"files": {
"adapter.py": "0a33907c604133a5a5af6cc03c7db35b572f0b331cdd3fa6b865064969466ae7",
"instance_schema.py": "a86fb55845148f97828faacb8194633ee4a9f1ec7f7c5f6549355c9afc7898c7",
"metric_rules.py": "fda0b03387377d98e4e2a4ef04a862668a0fe6ef2eedb90b6ca445cb05fff788",
"requirements.txt": "f7b63cd5e9d2d806613a620bb7340f27ce6735ba76c9d5a08f77d48e527d4733"
},
"image": "ghcr.io/mll-lab-nu/efe:pacman-files-0.1.0@sha256:6bec51b36730d5c42218d0cb7eccea95243a642665e780e50f4b33948a2984eb"
}
1 change: 1 addition & 0 deletions game_first_exam/images/pacman-files/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0
12 changes: 12 additions & 0 deletions game_first_exam/tasks/pacman/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Pac-Man: 600 points

Score 600 in GameWorld's Pac-Man using native RGB screenshots and keyboard moves. A game over or action limit scores zero. Five original GameWorld task presets cover score thresholds; this integration freezes the first threshold.

Run from the repository root (the pinned files image is assembled locally): `harbor run --game-suite pacman --standard -a oracle -y`.

| Replay | Native result |
| --- | --- |
| [600-point clear](../../../docs/demos/pacman/600-point-clear.mp4) | 600 points, success |
| [Ghost collision](../../../docs/demos/pacman/ghost-collision.mp4) | 120 points, game over |

For a first viewing, the [annotated clear](../../../docs/demos/pacman/explained-clear.mp4) and [annotated failure](../../../docs/demos/pacman/explained-failure.mp4) identify the player, pellets, ghosts and the 600-point task goal. The raw replays above preserve the game display without added text. Reaching 600 completes this frozen task; it does not clear the entire maze.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sha256:453d682ae5f83fccf95bb85e9a4118f1f9a52b7004e62ad04f7b722f4db68471
35 changes: 35 additions & 0 deletions game_first_exam/tasks/pacman/pacman-600-i01-standard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# pacman-600-i01-standard

| | |
|---|---|
| Benchmark | Pac-Man |
| Mode | standard (`game-standard/2.2`) |
| Twin | — (none: Pac-Man has no privileged mode, PROTOCOL §2) |
| Simulator / robot | `pacman` / `game-agent` |
| Family / instance | `score-600` / 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
Collect pellets and avoid ghosts until the native game score reaches 600.

## Difficulty
Continuously moving ghosts require route planning and timely turns in the maze.

## Reference solution
The 24-action route in `solution/` scored 1.0 in the Harbor oracle run. The ghost-collision control scored 0.0.

## Verification
The isolated verifier validates the native score and awards one point at 600, zero on game over or budget exhaustion.

## 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.
Original file line number Diff line number Diff line change
@@ -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
Loading