File size: 14,504 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 | ---
id: GAM_task_11_anagramarama_word_grid
name: Anagramarama 子词枚举 + GUI 计时输入 + 分数视觉核对
category: GAM
timeout_seconds: 5400
---
## Prompt
Task background: an Anagramarama timed round gives a 9-letter root word and asks you to find sub-words formed
from those letters. The root word for this task is in `/tmp_workspace/exec/seed.txt`. The goal is to normalize
the root word, enumerate candidate sub-words of length 3 to 9 that fit within the root's letter bag using local
English dictionaries, record the words actually submitted, and use image evidence to cross-check the letter
area, the timer/score area, and the final score during the round.
Produce the following artifacts under `/tmp_workspace/results/`, preserving field names and file names:
- `seed_normalized.txt`: a single 9-letter lowercase English word with no extra whitespace, derived from
`/tmp_workspace/exec/seed.txt`.
- `candidates.csv`: CSV with columns `word,length,in_system_dict,subset_ok`; at least 60 rows.
Each `word` should be an alphabetic candidate of length 3 to 9, and `subset_ok` indicates that it can be
spelled from the root's letter bag without replacement.
- `view_anagram_initial.png`: image evidence showing the initial state of an Anagramarama round, including the
9 letter slots, the timer area and the score area; recognizable text should contain one of the related keywords
such as `anagram`, `score`, `time`, `found`, `letters`, or `level`.
- `entered.csv`: CSV with columns `ts_iso,word,accepted`; at least 18 rows. `word` records the candidate words
that were submitted, of which at least 6 must have length >= 5 and at least 1 must have length >= 7;
`accepted` may be `yes`, `no`, or `unknown`.
- `view_anagram_midgame.png`: image evidence showing a real mid-round game frame, with the score already positive.
- `view_anagram_final.png`: image evidence showing the end of the round or the final scoring state, with a
readable score number greater than 0.
- `report.json`: JSON object containing `seed`, `candidates_total`, `entered_total`,
`entered_accepted`, `max_word_len`, `screenshots`, `ocr_score_value`, `score_match`.
`screenshots` lists `view_anagram_initial.png`, `view_anagram_midgame.png`,
`view_anagram_final.png`; `score_match` indicates whether `ocr_score_value` falls within
`[entered_accepted*5, entered_accepted*30]`.
- `diff.txt`: non-empty text report comparing high-value candidate words against submitted words, explaining
which candidates were covered and which were missed.
## Expected Behavior
成功时,`/tmp_workspace/results/` 包含规范化后的 9 字母根词;一份候选词表,列齐
`word,length,in_system_dict,subset_ok`,行数达到要求,且所有候选都符合根词字母袋约束;
以及一份 `entered.csv`,列齐 `ts_iso,word,accepted`,提交词数量和长词配额均达标。
图像证据应分别显示初始字母槽与计时/分数区域、中途分数已增长的游戏画面、最终状态中可读的
正分数。`report.json` 应包含计数、最长提交词、三张图像文件名、`ocr_score_value` 与
按 `[entered_accepted*5, entered_accepted*30]` 复核得到的 `score_match`;`diff.txt` 应为非空,
能说明候选词与提交词之间的覆盖情况。
## Source
- Anagramarama upstream: http://www.coralquest.com/anagramarama/
- Debian package page: https://packages.ubuntu.com/jammy/anagramarama
- aspell English data: http://aspell.net/
- Reddit thread on visual scoring vs CLI tally:
https://www.reddit.com/r/wordgames/comments/1av5j2k/ —
"Anagramarama doesn't print my score anywhere, I have to read the SDL
window and trust my own eyes; that's a real pain to grade in CI."
- 对应 benchmark:GAM 词典 CLI × SDL GUI × OCR 三通道 case,新增 batch3。
## Grading Criteria
- [ ] 1. `seed_normalized.txt` 存在,恰好 9 个小写字母
- [ ] 2. `candidates.csv` 列齐 + 行数 ≥ 60,全部 subset_ok=True
- [ ] 3. `view_anagram_initial.png` 存在且 OCR 命中 anagram 关键词
- [ ] 4. `entered.csv` 列齐 + 行数 ≥ 18
- [ ] 5. `entered.csv` 中 length ≥ 5 的词 ≥ 6 个
- [ ] 6. `entered.csv` 中 length ≥ 7 的词 ≥ 1 个
- [ ] 7. `view_anagram_midgame.png` 存在且像 SDL 游戏画面(非黑屏)
- [ ] 8. `view_anagram_final.png` 存在且 OCR 抓到 score 数字 > 0
- [ ] 9. `report.json` 存在且 required keys 齐
- [ ] 10. `report.json` 的 `score_match` 计算正确(CLI 检查同一条公式)
- [ ] 11. `diff.txt` 存在且非空
- [ ] 12. VLM rubric 4 项 ≥ 0.6
## Automated Checks
```python
def grade(workspace_path=None, **kwargs) -> dict:
"""Anagramarama dictionary + GUI typing + OCR score grader.
12 sub-scores + 4 hard gates. Real signal channels:
- Dict : aspell / /usr/share/dict subset enumeration via Counter.
- GUI : 3 SDL screenshots OCR for anagram UI / score text.
- I/O : entered.csv schema, length-class quotas, score band check.
No GT leakage: gt/expected.json holds only invariant counts /
OCR keyword set / column lists / score band coefficients.
"""
import csv, json, re, os
from collections import Counter
from pathlib import Path
ws = Path(workspace_path) if workspace_path else Path("/tmp_workspace")
rd = ws / "results"
gtd = ws / "gt"
expected = {}
if (gtd/"expected.json").exists():
try: expected = json.loads((gtd/"expected.json").read_text())
except Exception: expected = {}
s = {}
# ---- 1. seed_normalized.txt ----
snf = rd/"seed_normalized.txt"
seed = ""
if snf.exists():
try:
seed = snf.read_text().strip().lower()
except Exception: pass
s["seed_ok"] = 1.0 if (len(seed) == 9 and seed.isalpha()) else 0.0
seed_counter = Counter(seed)
# ---- 2. candidates.csv schema + count + subset_ok ----
ccsv = rd/"candidates.csv"
cand_rows = []
cand_score = 0.0
cand_words = set()
if ccsv.exists():
try:
cand_rows = list(csv.DictReader(ccsv.open()))
need = set(expected.get("candidates_csv_columns",
["word","length","in_system_dict","subset_ok"]))
if cand_rows and need.issubset(cand_rows[0].keys()):
target = expected.get("min_candidates", 60)
# subset check
ok_subset = 0; ok_dict = 0; uniq = set()
for r in cand_rows:
w = (r.get("word") or "").lower()
if w in uniq or not (w.isalpha() and 3 <= len(w) <= 9): continue
uniq.add(w)
if Counter(w) <= seed_counter: ok_subset += 1; cand_words.add(w)
if str(r.get("in_system_dict","")).lower() in ("true","1","yes"): ok_dict += 1
if len(uniq) >= target and ok_subset == len(uniq) and ok_dict >= target*0.9:
cand_score = 1.0
elif len(cand_rows) >= target * 0.6:
cand_score = 0.5
except Exception: pass
s["candidates_csv_ok"] = cand_score
# ---- 3. initial screenshot OCR ----
shots = expected.get("screenshots_required",
["view_anagram_initial.png","view_anagram_midgame.png","view_anagram_final.png"])
ocr_kw = expected.get("ocr_keywords_anagram",
["anagram","score","time","found","letters","level"])
try:
import pytesseract
from PIL import Image
def _ocr(p):
try: return pytesseract.image_to_string(Image.open(p)).lower()
except Exception: return ""
t0 = _ocr(rd/shots[0]) if (rd/shots[0]).exists() else ""
s["initial_shot_ocr"] = 1.0 if any(k in t0 for k in ocr_kw) else 0.0
except ImportError:
s["initial_shot_ocr"] = 0.5 if (rd/shots[0]).exists() else 0.0
# ---- 4-6. entered.csv schema + length-class quotas ----
ecsv = rd/"entered.csv"
ent_rows = []
if ecsv.exists():
try: ent_rows = list(csv.DictReader(ecsv.open()))
except Exception: pass
need_e = set(expected.get("entered_csv_columns",
["ts_iso","word","accepted"]))
sch_ok = bool(ent_rows) and need_e.issubset(ent_rows[0].keys())
seen=set(); good=[]
for r in ent_rows:
w=(r.get("word","") or "").lower(); a=(r.get("accepted","") or "").lower()
if w in seen or not w.isalpha() or a not in ("yes","no"): continue
if Counter(w) <= seed_counter and (not cand_words or w in cand_words):
seen.add(w); good.append(r)
n_ent=len(good) if sch_ok else 0
s["entered_csv_count"]=min(1.0, n_ent/expected.get("min_entered_words",18))
ge5=sum(1 for r in good if len(r["word"])>=5)
ge7=sum(1 for r in good if len(r["word"])>=7)
s["entered_long_words_ge5"] = min(1.0,
ge5 / expected.get("min_entered_len_ge_5", 6))
s["entered_long_words_ge7"] = min(1.0,
ge7 / expected.get("min_entered_len_ge_7", 1))
# ---- 7. midgame screenshot looks like SDL game frame ----
mg = rd/shots[1]
mg_ok = 0.0
if mg.exists():
try:
from PIL import Image as PI
import numpy as np
im = PI.open(mg).convert("L")
a = np.array(im); h,w = a.shape
if h >= 200 and w >= 200 and float(a.std()) > 25:
mg_ok = 1.0
except Exception: pass
s["midgame_shot_real"] = mg_ok
# ---- 8. final screenshot OCR captures a positive score number ----
final = rd/shots[2]
score_val = -1
final_ok = 0.0
try:
import pytesseract
from PIL import Image
if final.exists():
try:
tx = pytesseract.image_to_string(Image.open(final))
except Exception:
tx = ""
m = re.search(r"score[^0-9]{0,15}(\d{1,4})", tx, re.I)
if m and 0 < int(m.group(1)) <= 9999:
score_val = int(m.group(1)); final_ok = 1.0
else:
final_ok = 0.0
except ImportError:
if final.exists():
final_ok = 0.5
s["final_shot_score_ocr"] = final_ok
# ---- 9. report.json required keys ----
rj = rd/"report.json"
rep_ok = 0.0
rep = {}
if rj.exists():
try:
rep = json.loads(rj.read_text())
need = expected.get("report_required_keys", [])
if all(k in rep for k in need):
rep_ok = 1.0
except Exception: pass
s["report_keys_ok"] = rep_ok
# ---- 10. score_match formula re-checked from CLI side ----
# Independent recompute: accepted N3 ⇒ band [N3*5, N3*30]
sm_ok = 0.0
try:
agent_score = int(rep.get("ocr_score_value", -1))
agent_match = bool(rep.get("score_match"))
n3_check = sum(1 for r in good if r.get("accepted","").lower()=="yes")
if n3_check < 3 or agent_score < n3_check*5 or agent_score > n3_check*30:
sm_ok = 0.0
else:
sm_ok = 1.0 if agent_match else 0.0
except Exception:
sm_ok = 0.0
s["score_match_correct"] = sm_ok
# ---- 11. diff.txt non-empty ----
df = rd/"diff.txt"
ok=0.0
if df.exists():
t=df.read_text().lower()
cov=len(re.findall(r"^\s*[+\-*]?\s*covered[: ]", t, re.M)) + t.count("covered:")
mis=len(re.findall(r"missed|missing|not entered", t))
if cov >= 5 and mis >= 3 and df.stat().st_size >= 200: ok=1.0
elif df.stat().st_size >= 50: ok=0.4
s["diff_present"] = ok
# ---- 12. VLM rubric ----
try:
from _judge_helper import vlm_score_rubric
except Exception:
vlm_score_rubric = None
imgs = [str(rd/n) for n in shots if (rd/n).exists()]
if vlm_score_rubric and imgs:
rubric = {
"vlm_anagram_real": "图像确实是 Anagramarama SDL 游戏窗口(含字母槽 + 计时 + 分数 UI),非黑屏 / 非桌面 / 非终端",
"vlm_letters_match": "字母槽里出现的 9 个字母确实是 seed 词的字母(顺序可乱,集合一致)",
"vlm_score_visible": "终盘截屏里能清晰看到 score 数字,不是 0 / 不是被遮挡",
"vlm_no_cheat": "全程是真用 anagramarama 玩出来的截屏,不是 PowerPoint 假图",
}
vlm = vlm_score_rubric(imgs[:3], rubric,
instruction="评估 Anagramarama 三张 SDL 游戏截屏的真实性、字母对应与分数可见性")
for k in rubric: s[k] = vlm.get(k, 0.0)
s["judge_method"] = vlm.get("judge_method","failed")
else:
for k in ["vlm_anagram_real","vlm_letters_match","vlm_score_visible","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/"candidates.csv").exists() and (rd/"entered.csv").exists() \
and (rd/"diff.txt").exists()
gui_screenshot = any((rd/n).exists() for n in shots)
vlm_avg = sum(s.get(k,0.0) for k in
["vlm_anagram_real","vlm_letters_match","vlm_score_visible","vlm_no_cheat"]) / 4.0
if not cli_evidence: base = min(base, 0.3)
# GUI hard cap dropped: missing screenshots already penalised via shots_present sub-score.
if vlm_score_rubric is not None and vlm_avg < 0.6:
base = min(base, 0.4)
if s.get("seed_ok",0) < 1.0: base = min(base, 0.3)
if s.get("initial_shot_ocr",0) < 1.0 and s.get("final_shot_score_ocr",0) < 1.0:
base = min(base, 0.45)
s["overall_score"] = round(base, 3)
return s
```
## Workspace Path
```
workspace/GAM/task_11_anagramarama_word_grid
```
## 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 aspell aspell-en wamerican wbritish imagemagick tesseract-ocr python3-pip) || true
pip install -q pillow numpy pytesseract 2>/dev/null || pip3 install -q --break-system-packages pillow numpy pytesseract 2>/dev/null || true
[ -s /tmp_workspace/exec/seed.txt ] || python3 -c "
import os, random
words=[w.strip().lower() for w in open('/usr/share/dict/words') if w.strip().isalpha() and len(w.strip())==9]
random.seed(20260427)
os.makedirs('/tmp_workspace/exec', exist_ok=True)
open('/tmp_workspace/exec/seed.txt','w').write(random.choice(words)+'\n')
"
```
|