File size: 20,126 Bytes
71e9dba | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | ---
id: GAM_task_13_hedgewars_lua_mission_debug
name: Hedgewars 自定义训练 Lua 任务修复 + Frontend+对战双视图通关
category: GAM
timeout_seconds: 5400
---
## Prompt
Background: `/tmp_workspace/exec/scripts/CrateCrash.lua` is a hand-crafted Hedgewars training
mission. The player should collect 3 health crates on a small Bamboo-themed island to
complete the "Crate Crash Course". The current script has several issues spanning team,
ammo and map configuration that you need to locate yourself.
Your goal is to parse the original Lua mission, record reproduction evidence, produce a
syntactically valid and numerically sane fixed version, and provide image evidence of the
mission list, the bug states, and the completion state.
Please produce the following files, keeping field names and file names exactly as specified:
- `/tmp_workspace/results/before/CrateCrash.lua`: an unmodified copy of the original mission script, for diff bookkeeping.
- `/tmp_workspace/results/parse_before.json`: JSON object containing the six keys
`map`, `theme`, `team`, `hogs`, `ammo`, `crates`; the `crates` list must have length 3.
Recommended: `team` includes `name,color_hex,grave,fort,voicepack,flag`,
`hogs` entries include `name,hat,spawn`,
`ammo` includes `amBazooka,amGrenade,amSkip`,
`crates` entries include `index,x,y`.
- `/tmp_workspace/results/bugs.json`: JSON object containing three items:
`bug_team_color_invisible` (with `detected,color_hex`, optionally `theme,rationale`),
`bug_player_no_ammo` (with `detected,weapons_with_zero`),
`bug_crate_offscreen` (with `detected,crate_index,y`, optionally `map_max_y`).
Each item's fields should document the colour, ammo or coordinate evidence that triggered detection.
- `/tmp_workspace/work/scripts/CrateCrash_fixed.lua`: the fixed Lua script; it must be
syntactically valid, the colour passed to `AddTeam(...)` must be a legal hex value and
not close to `0xFFFFFF`, the ammo counts for `amBazooka` and `amGrenade` must each be
at least 5, and the `y` coordinate of the second `SpawnHealthCrate` must lie within
`[0, 2048]`.
- `/tmp_workspace/results/view_frontend.png`: image evidence showing that, before the fix,
the mission appears in the training mission list, with visible text such as `Training`,
`Single`, `Mission`, `Crate` or `Course`.
- `/tmp_workspace/results/view_play_bug.png`: image evidence showing one of the real bug
states in the unfixed mission — e.g. character/name tag invisibility, abnormal
Bazooka/ammo state, or insufficient health crates; recognisable text should include
one of `Trainee`, `Rookie`, `Bazooka`, `Crates` or `ammo`.
- `/tmp_workspace/results/view_frontend_after.png`: image evidence showing the training
mission list after the fix, with the mission still visible and selectable.
- `/tmp_workspace/results/view_play_finish.png`: image evidence showing the mission
completion state, with result text such as `Mission complete`, `All crates collected`
or `You won` visible.
- `/tmp_workspace/results/engine.log`: a non-empty log containing mission/ammo-related
markers such as `Trainee`, `Rookie`, `ammo` or `bazooka`.
- `/tmp_workspace/results/parse_after.json`: JSON object with the same schema as
`parse_before.json`, reflecting the structure of the fixed script.
- `/tmp_workspace/results/diff.txt`: text diff between the original script and
`CrateCrash_fixed.lua`, with between 6 and 200 lines.
- `/tmp_workspace/results/report.json`: JSON object containing `bugs_found`,
`fixes_applied`, `team_color_after`, `ammo_after`, `crates_after`,
`playthrough_finished`, `screenshots`, `engine_log_lines`; `screenshots` lists the
four image evidence file names.
## Expected Behavior
成功时,`parse_before.json` 和 `parse_after.json` 都以
`map/theme/team/hogs/ammo/crates` 描述任务结构,且包含 3 个血包条目;`bugs.json`
对队伍颜色不可见、玩家关键武器无弹药、血包越界三类问题均给出 `detected=true`
和可核查字段。`/tmp_workspace/work/scripts/CrateCrash_fixed.lua` 应语法有效,颜色不接近白色,
`amBazooka` 与 `amGrenade` 弹药数达标,第二个血包的 `y` 坐标回到允许地图范围内。
图像证据应分别显示修复前训练任务列表、修复前问题状态、修复后训练任务列表和任务完成结果;
完成图像应可见 `Mission complete`、`All crates collected` 或 `You won`。`engine.log`
应含任务或弹药相关标记,`diff.txt` 行数处于允许范围,`report.json` 应汇总问题、修复、
修复后颜色/弹药/血包坐标、完成状态、图像文件名和日志行数。
## Source
- Hedgewars Lua API reference:
https://www.hedgewars.org/kb/LuaAPI
- Reference training mission (real upstream file):
https://github.com/hedgewars/hw/blob/master/share/hedgewars/Data/Missions/Training/Basic_Training_-_Bazooka.lua
- Hedgewars `hwengine` CLI flags:
https://www.hedgewars.org/kb/EngineCommandLineParameters
- Forum thread on white-on-snow team colour bug:
https://hedgewars.org/forum/threads/team-colour-invisible-on-bamboo
- 对应 benchmark:GAM 视觉×文件双通道 Lua 任务修复 case
## Grading Criteria
- [ ] 1. `parse_before.json` schema 完整(map + theme + team + hogs +
ammo + crates 六 key 都在,crates 列表长度 == 3)
- [ ] 2. `bugs.json` 三个 bug 都 detected=true 且证据字段非空
- [ ] 3. `work/scripts/CrateCrash_fixed.lua` 存在且 `luac -p` 通过
- [ ] 4. fixed 脚本里 `AddTeam(...)` 第二个实参是合法十六进制颜色,且
与 `0xFFFFFF` 的距离 ≥ 0x808080(即不是接近白)
- [ ] 5. fixed 脚本里 `amBazooka` 与 `amGrenade` 的 ammo count 都 ≥ 5
- [ ] 6. fixed 脚本里第 2 个 `SpawnHealthCrate` 调用的 y 坐标在 [0, 2048]
区间内
- [ ] 7. `view_frontend.png` / `view_frontend_after.png` 都存在且 OCR
命中 "Training"/"Single"/"Mission"/"Crate" 之一
- [ ] 8. `view_play_bug.png` 存在且看起来是真游戏画面(OCR 命中 "Trainee"
/ "Rookie" / "Bazooka" / "Crates" 之一,或 VLM 判断是真窗口)
- [ ] 9. `view_play_finish.png` OCR 命中 "Mission complete" /
"All crates collected" / "You won" 之一
- [ ] 10. `engine.log` 存在且非空,含 "Trainee" / "Rookie" / "ammo" 字样
- [ ] 11. `diff.txt` 存在,行数在 [6, 200] 区间
- [ ] 12. VLM rubric 4 项 ≥ 0.6
## Automated Checks
```python
def grade(workspace_path=None, **kwargs) -> dict:
"""Hedgewars Lua training-mission repair + GUI playthrough verifier.
Sub-scores (12) + 3 hard gates. Real signal channels:
- File: regex parse of the Lua script for AddTeam / AddAmmo /
SpawnHealthCrate; numeric checks on team color hex,
ammo counts, crate y coord.
- GUI : 4 screenshots OCR for frontend / engine / finish overlay.
- Run : engine.log captures stderr from hwengine.
No GT leakage: gt/expected.json holds invariant counts only
(e.g. number of bugs, OCR keyword set, map_max_y, diff bounds).
"""
import json, os, re, subprocess
from pathlib import Path
ws = Path(workspace_path) if workspace_path else Path("/tmp_workspace")
rd = ws / "results"
work = ws / "work"
gt_dir = ws / "gt"
expected = {}
if (gt_dir / "expected.json").exists():
try: expected = json.loads((gt_dir/"expected.json").read_text())
except Exception: expected = {}
s = {}
# ---- 1. parse_before.json schema ----
pb = rd / "parse_before.json"
schema_ok = 0
if pb.exists():
try:
d = json.loads(pb.read_text())
need = {"map","theme","team","hogs","ammo","crates"}
if (need.issubset(d.keys())
and isinstance(d.get("crates"), list)
and len(d["crates"]) == 3):
schema_ok = 1
except Exception: pass
s["parse_before_schema"] = float(schema_ok)
# ---- 2. bugs.json all 3 bugs detected with evidence ----
bj = rd / "bugs.json"
bugs_hit = 0
if bj.exists():
try:
b = json.loads(bj.read_text())
color_hex_gt = str(expected.get("broken_team_color_hex", "FFFFFF")).upper()
crate_idx_set = expected.get("broken_crate_index_set", [1, 2])
try: crate_idx_set = list(crate_idx_set)
except Exception: crate_idx_set = [1, 2]
offscreen_y_min = int(expected.get("map_max_landscape_y", 2048)) + 1
for k, must in [
("bug_team_color_invisible", ["color_hex"]),
("bug_player_no_ammo", ["weapons_with_zero"]),
("bug_crate_offscreen", ["crate_index","y"]),
]:
v = b.get(k, {})
ok = bool(v.get("detected")) and all(m in v for m in must)
if ok and k == "bug_team_color_invisible":
ok = color_hex_gt in str(v.get("color_hex","")).upper()
if ok and k == "bug_player_no_ammo":
wz = [str(x).lower() for x in (v.get("weapons_with_zero") or [])]
ok = ("ambazooka" in wz) and ("amgrenade" in wz)
if ok and k == "bug_crate_offscreen":
ok = (int(v.get("crate_index",-1)) in crate_idx_set) and \
int(v.get("y",0)) >= offscreen_y_min
if ok: bugs_hit += 1
except Exception: pass
s["bugs_detected_with_evidence"] = bugs_hit / 3.0
# ---- 3-6. fixed lua parses & invariants ----
fixed_paths = [work/"scripts/CrateCrash_fixed.lua",
ws/"exec/scripts/CrateCrash_fixed.lua"]
fixed = next((p for p in fixed_paths if p.exists()), None)
luac_ok = color_ok = ammo_ok = crate_ok = 0.0
txt = ""
if fixed:
try: txt = fixed.read_text(errors="ignore")
except Exception: txt = ""
try:
r = subprocess.run(["luac","-p",str(fixed)],
capture_output=True, timeout=10)
luac_ok = 1.0 if r.returncode == 0 else 0.0
except Exception:
# fallback: structural sanity
if "function onGameInit" in txt and "AddTeam" in txt:
luac_ok = 0.7
s["fixed_lua_parses"] = luac_ok
if txt:
# Team color: AddTeam(<name>, 0xRRGGBB, ...)
m = re.search(
r"AddTeam\s*\(\s*[^,]+,\s*0x([0-9A-Fa-f]{6})\b", txt)
if m:
hx = int(m.group(1), 16)
white = 0xFFFFFF
# crude colour distance: how far each channel from 0xFF
dr = abs(((hx>>16)&0xFF) - 0xFF)
dg = abs(((hx>>8 )&0xFF) - 0xFF)
db = abs(((hx )&0xFF) - 0xFF)
if (dr + dg + db) >= 0x180: # ≥ ~half-white in L1
near_white = (dr + dg + db) < 0x240
chan_dark = max((hx>>16)&0xFF,(hx>>8)&0xFF,hx&0xFF) < 0xC0
if (not near_white) and chan_dark:
color_ok = 1.0
# Ammo counts for amBazooka and amGrenade
baz = re.search(
r"AddAmmo\s*\(\s*\w+\s*,\s*amBazooka\s*,\s*(\d+)\s*\)", txt)
gre = re.search(
r"AddAmmo\s*\(\s*\w+\s*,\s*amGrenade\s*,\s*(\d+)\s*\)", txt)
if baz and gre and int(baz.group(1)) >= 5 and int(gre.group(1)) >= 5:
ammo_ok = 1.0
# Crates: collect all SpawnHealthCrate(x, y) in order
crates = [(int(a), int(b)) for a,b in re.findall(
r"SpawnHealthCrate\s*\(\s*(-?\d+)\s*,\s*(-?\d+)\s*\)", txt)]
max_y = expected.get("map_max_landscape_y", 2048)
if (len(crates) >= 3
and 0 <= crates[1][1] <= max_y
and 0 <= crates[0][1] <= max_y
and 0 <= crates[2][1] <= max_y):
crate_ok = 1.0
s["fixed_team_color"] = color_ok
s["fixed_ammo_counts"] = ammo_ok
s["fixed_crates_in_map"] = crate_ok
# ---- 7. frontend screenshots present + OCR ----
def _is_real_capture(p):
# Content-based realness check: any non-trivial PNG ≥ 800×600 with
# enough colour diversity counts as real. Drops the previous narrow
# resolution whitelist that rejected legitimate KasmVNC screenshots
# at non-standard sizes (e.g. 1024×768, 1366×768).
try:
from PIL import Image
im = Image.open(p); w, h = im.size
if w < 800 or h < 600:
return False
try:
import collections
px = list(im.convert("RGB").resize((64, 64)).getdata())
return len(collections.Counter(px)) >= 200
except Exception:
return True
except Exception:
return False
shots_fe = ["view_frontend.png","view_frontend_after.png"]
fe_present = sum(1 for n in shots_fe if (rd/n).exists() and _is_real_capture(rd/n))
s["frontend_shots_present"] = fe_present / 2.0
fe_kw = expected.get("frontend_keywords",
["training","mission","crash","course","crate","play","single"])
try:
import pytesseract
from PIL import Image
fe_ocr_hits = 0
for n in shots_fe:
p = rd/n
if p.exists():
try:
tx = pytesseract.image_to_string(Image.open(p)).lower()
if any(k in tx for k in fe_kw):
fe_ocr_hits += 1
except Exception: pass
s["frontend_shots_ocr"] = fe_ocr_hits / 2.0
except ImportError:
s["frontend_shots_ocr"] = 0.5
# ---- 8. play bug screenshot present + OCR ----
pb_shot = rd/"view_play_bug.png"
s["play_bug_shot_present"] = 1.0 if (pb_shot.exists() and _is_real_capture(pb_shot)) else 0.0
eng_kw = expected.get("engine_keywords",
["trainee","rookie","crates","bazooka","ammo"])
try:
import pytesseract
from PIL import Image
if pb_shot.exists():
try:
tx = pytesseract.image_to_string(Image.open(pb_shot)).lower()
except Exception:
tx = ""
hits = sum(1 for k in eng_kw if k in tx)
s["play_bug_shot_hud_ocr"] = 1.0 if hits >= 1 else 0.0
else:
s["play_bug_shot_hud_ocr"] = 0.0
except ImportError:
s["play_bug_shot_hud_ocr"] = 0.5 if pb_shot.exists() else 0.0
# ---- 9. play finish screenshot present + OCR ----
pf_shot = rd/"view_play_finish.png"
s["play_finish_shot_present"] = 1.0 if (pf_shot.exists() and _is_real_capture(pf_shot)) else 0.0
fin_kw = expected.get("complete_keywords",
["mission complete","all crates collected","you won"])
try:
import pytesseract
from PIL import Image
if pf_shot.exists():
try:
tx = pytesseract.image_to_string(Image.open(pf_shot)).lower()
except Exception:
tx = ""
s["play_finish_shot_ocr"] = 1.0 if any(k in tx for k in fin_kw) else 0.0
else:
s["play_finish_shot_ocr"] = 0.0
except ImportError:
s["play_finish_shot_ocr"] = 0.5 if pf_shot.exists() else 0.0
# ---- 10. engine.log non-empty + has team / ammo markers ----
el = rd/"engine.log"
el_ok = 0.0
if el.exists() and el.stat().st_size > 8:
try:
t = el.read_text(errors="ignore").lower()
hits = sum(1 for k in ["trainee","rookie","ammo","bazooka"] if k in t)
real_markers = sum(1 for k in
["hwengine","sdl","opengl","loading script","gameflags","seed ","fps:"]
if k in t)
el_ok = 1.0 if (hits>=2 and real_markers>=2 and el.stat().st_size>=512) else 0.0
except Exception: pass
s["engine_log_ok"] = el_ok
# ---- 11. diff.txt sanity ----
df = rd/"diff.txt"
dlines = 0
if df.exists():
try: dlines = sum(1 for _ in df.open())
except Exception: dlines = 0
lo = expected.get("diff_min_lines", 6)
hi = expected.get("diff_max_lines", 200)
s["diff_in_range"] = 1.0 if lo <= dlines <= hi else 0.0
# ---- 11b. report.json structural validation (Prompt deliverable #12) ----
rp = rd / "report.json"; rep_ok = 0.0
if rp.exists():
try:
r = json.loads(rp.read_text())
need = ["bugs_found", "fixes_applied", "team_color_after",
"ammo_after", "crates_after", "playthrough_finished",
"screenshots", "engine_log_lines"]
present = sum(1 for k in need if k in r)
if (present == len(need)
and r.get("playthrough_finished")
and isinstance(r.get("screenshots"), list)
and len(r.get("screenshots", [])) >= 4):
rep_ok = 1.0
elif present >= max(4, len(need) - 2):
rep_ok = 0.5
except Exception:
pass
s["report_json_ok"] = rep_ok
# ---- 12. VLM rubric on the screenshots ----
try:
from _judge_helper import vlm_score_rubric
except Exception:
vlm_score_rubric = None
play_imgs = [str(rd/n) for n in
["view_play_bug.png","view_play_finish.png","view_frontend_after.png"]
if (rd/n).exists()]
if vlm_score_rubric and play_imgs:
rubric = {
"vlm_hedgewars_real": "图像确实是 Hedgewars 前端或战斗画面(含菜单 / 小刺猬 / HUD 弹药面板),不是黑屏或主菜单 placeholder",
"vlm_team_visible": "fixed 后小刺猬名牌 / 帽子 在 Bamboo 雪地背景下是可见的 (颜色对比明显)",
"vlm_finish_overlay": "通关截屏里能看到 Mission complete / All crates collected / You won 之类提示",
"vlm_no_cheat": "看上去是真实通过前端+引擎通关的,不是把 Demo 文件伪造或叠图",
}
vlm = vlm_score_rubric(play_imgs[:3], rubric,
instruction="评估 Hedgewars 训练任务修复 + 通关截图的真实性与可视一致性")
for k in rubric: s[k] = vlm.get(k, 0.0)
s["judge_method"] = vlm.get("judge_method","failed")
else:
for k in ["vlm_hedgewars_real","vlm_team_visible",
"vlm_finish_overlay","vlm_no_cheat"]:
s[k] = 0.5
# ---- aggregate + hard gates ----
nums = [v for v in s.values() if isinstance(v,(int,float))]
base = sum(nums)/len(nums) if nums else 0.0
cli_evidence = ((rd/"parse_before.json").exists()
and (rd/"bugs.json").exists()
and (rd/"diff.txt").exists())
gui_screenshot = any((rd/n).exists() for n in
["view_frontend.png","view_frontend_after.png",
"view_play_bug.png","view_play_finish.png"])
vlm_avg = sum(s.get(k,0.0) for k in
["vlm_hedgewars_real","vlm_team_visible",
"vlm_finish_overlay","vlm_no_cheat"]) / 4.0
if not cli_evidence: base = min(base, 0.4)
# GUI hard cap dropped: missing screenshots already penalised via per-shot sub-scores.
# Only enforce VLM caps when the helper actually ran (otherwise the
# 0.5 fallback would cap at 0.4 even though no rubric was applied).
if vlm_score_rubric is not None and vlm_avg < 0.6:
base = min(base, 0.4)
if vlm_score_rubric is not None and s.get("vlm_no_cheat",0.0) < 0.5:
base = min(base, 0.35)
if s.get("fixed_lua_parses",0) < 1.0: base = min(base, 0.5)
if s.get("play_finish_shot_ocr",0)<1.0: base = min(base, 0.45)
s["overall_score"] = round(base, 3)
return s
```
## Workspace Path
```
workspace/GAM/task_13_hedgewars_lua_mission_debug
```
## Skills
```
```
## Env
```
```
## Warmup
```bash
mkdir -p /tmp_workspace/results /tmp_workspace/state /tmp_workspace/exec
which tesseract || (apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -o Acquire::Retries=10 install -y -qq imagemagick tesseract-ocr lua5.3 libgl1 python3-pip) || true
pip install -q pillow numpy pytesseract luaparser 2>/dev/null || pip3 install -q --break-system-packages pillow numpy pytesseract luaparser 2>/dev/null || true
```
|