geometry: scanline cellsTouched, differential + independent oracle tests, prototype corpus
cellsTouched is now a scanline over cell rows (prototype per-cell version kept test-only in tests/refold.nim). Differential tests (random polygons, concave, grid-aligned) and a brute-force explored oracle (0.5 px tolerance) cover it; regression corpus = prototype leak-run polygons. moveBlocked leaves geometry.nim (replaced by server/moverules.nim next); geometry primitives exported. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
## One-off corpus extractor (dev-time only; tests never read prototype paths).
|
||||
## usage: nim c -r tools/mkcorpus.nim prototype-server-vision/results/leak-A.jsonl prototype-server-vision/results/leak-B.jsonl > tests/fixtures/corpus.jsonl
|
||||
## Replays the GM socket (token positions, door states per gseq) and emits one line per player `vision` message:
|
||||
## {"src":"A|B","g":gseq,"id":"A|B","pos":[x,y],"open":[door ids],"poly":[[x,y]..]} (poly = what the prototype server sent,
|
||||
## computed by the old geometry.nim; "open" = ALL open doors, initial states included). The scene (walls, radius, cell) is tests/fixtures/scene.json.
|
||||
import std/[json, os, tables, algorithm]
|
||||
for fi, path in commandLineParams():
|
||||
let src = if fi == 0: "A" else: "B"
|
||||
var pos: Table[string, JsonNode]
|
||||
var open: Table[int, bool] # initial door states from the scene fixture, then the GM log
|
||||
for w in parseFile("tests/fixtures/scene.json")["walls"]:
|
||||
if w{"door"}.getBool: open[w["id"].getInt] = w["open"].getBool
|
||||
var msgs: seq[JsonNode]
|
||||
for line in lines(path):
|
||||
let j = parseJson(line)
|
||||
if j["k"].getStr == "msg": msgs.add j
|
||||
# GM log first (gseq-ordered), then answer each vision message from the truth at its gseq
|
||||
var gm: seq[JsonNode]
|
||||
for j in msgs:
|
||||
if j["who"].getStr == "GM": gm.add j["m"]
|
||||
var gi = 0
|
||||
for j in msgs:
|
||||
let who = j["who"].getStr
|
||||
let m = j["m"]
|
||||
if who in ["A", "B"] and m["t"].getStr == "vision":
|
||||
let g = m["gseq"].getInt
|
||||
while gi < gm.len and gm[gi]["gseq"].getInt <= g:
|
||||
let x = gm[gi]; inc gi
|
||||
case x["t"].getStr
|
||||
of "token": pos[x["id"].getStr] = x["pos"]
|
||||
of "door": open[x["id"].getInt] = x["open"].getBool
|
||||
else: discard
|
||||
var ids: seq[int]
|
||||
for k, v in open:
|
||||
if v: ids.add k
|
||||
ids.sort
|
||||
echo $(%*{"src": src, "g": g, "id": who, "pos": pos[who], "open": ids, "poly": m["polys"][0]})
|
||||
Reference in New Issue
Block a user