moverules: blocked policy set/keep/clear (GM moves and placements set/clear, KEEP while any wall overlaps); tests; mutations k, l

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-08 18:47:39 +01:00
co-authored by Claude Sonnet 5.5
parent 0e0b1a6052
commit 388e901541
4 changed files with 116 additions and 34 deletions
+19 -12
View File
@@ -6,19 +6,19 @@
## 2. in bounds, and |d - s| <= stepCap (token vision radius if it has vision and sets one, else scene default);
## 3. per blocking wall W: start overlapping W (dist(s,W) < r, "escape"): allowed iff the path does not cross W
## farther than EscapeEps from s AND dist(d,W) >= r; otherwise swept circle: allowed iff dist(seg s->d, W) >= r.
## GM move: bounds only (no walls, no cap, ignores `blocked`). GM moves/placements never set `blocked`.
## `blocked`: set when an added wall / closed door has dist(token centre, W) < r; cleared when that wall is removed,
## that door opened, or the GM clears it (gmClearBlocked). wall update = remove then add.
## GM move: bounds only (no walls, no cap, ignores `blocked`), then blocked = overlaps any blocking wall.
## `blocked` ("stuck", DESIGN 5.5): overlap = dist(token centre, W) < r. SET: wall added / updated / door closed on a
## token; GM places or moves a token onto a blocking wall. KEEP: stays while ANY blocking wall overlaps. CLEAR: wall
## removed / door opened -> tokens that overlapped it get blocked = overlaps any remaining blocking wall; GM move to a
## free spot; gmClearBlocked (unconditional). Only tokens touched by the event change. wall update = remove then add.
##
## Thresholds (px unless noted):
## EscapeEps = 1e-6: a crossing this close to the start is "the token stands on the wall", not a crossing. A token
## within 1e-6 of a wall can only exist via GM placement/edit (a player move keeps dist >= r), so this cannot be
## used to tunnel; 1e-6 is far below one pixel and far above float noise at world scale (|coords| < 1e5, ~1e-11).
## geometry.Eps = 1e-9 (parallel/collinear/touch tolerance, shared with the vision code).
## Interpretation notes (DESIGN 5.5 "Unconfirmed"): (b) opening a door clears `blocked` for every token whose circle
## overlaps that door even if another closed wall still overlaps it; removing/updating a wall likewise. Only a
## BLOCKING wall's removal clears (removing an already-open door changes nothing). removeWall shifts later wall
## indices down (dense ids); M3 owns id stability.
## Interpretation notes: removing/opening affects only a BLOCKING wall (removing an open door changes nothing).
## removeWall shifts later wall indices down (dense ids); M3 owns id stability.
## Escape corner case (spec-normative): an escaping token may graze closer to W than it started, mid-path; only
## crossing and the destination are checked. Moving along the wall's own line counts as crossing.
## Not checked here: path crossing a wall W2 whose capsule distance is >= r is fine by definition.
@@ -97,6 +97,12 @@ proc stepCap*(sc: Scene, t: Token): float =
proc inBounds(sc: Scene, p: Vec): bool = # written so NaN fails
p.x >= 0 and p.y >= 0 and p.x <= sc.w and p.y <= sc.h
proc overlaps(sc: Scene, t: Token, w: Wall): bool = segDist(t.pos, w.a, w.b) < sc.tokenRadius
proc overlapsAny(sc: Scene, t: Token): bool =
for w in sc.walls:
if w.blocks and overlaps(sc, t, w): return true
proc nack(s: Vec): MoveResult = MoveResult(kind: mkNack, pos: s)
proc moveToken*(sc: var Scene, who: Actor, ti: int, d: Vec): MoveResult =
@@ -113,15 +119,15 @@ proc moveToken*(sc: var Scene, who: Actor, ti: int, d: Vec): MoveResult =
if hypot(dd.x, dd.y) > stepCap(sc, sc.tokens[ti]): return nack(s)
if not pathClear(sc.walls, s, d, sc.tokenRadius): return nack(s)
sc.tokens[ti].pos = d
if who.role == roleGM: sc.tokens[ti].blocked = overlapsAny(sc, sc.tokens[ti])
MoveResult(kind: mkAck, pos: d)
# ---- `blocked` bookkeeping -------------------------------------------------------------------------------------
proc overlaps(sc: Scene, t: Token, w: Wall): bool = segDist(t.pos, w.a, w.b) < sc.tokenRadius
proc addToken*(sc: var Scene, t: Token): int =
## GM placement: ignores walls, never computes `blocked` (stored as given)
## GM placement: ignores walls; blocked = given flag or overlapping a blocking wall
sc.tokens.add t
sc.tokens[^1].blocked = t.blocked or overlapsAny(sc, t)
sc.tokens.high
proc gmClearBlocked*(sc: var Scene, ti: int) =
@@ -135,7 +141,7 @@ proc applyAdded(sc: var Scene, w: Wall) =
proc applyRemoved(sc: var Scene, w: Wall) =
if w.blocks:
for i in 0 ..< sc.tokens.len:
if overlaps(sc, sc.tokens[i], w): sc.tokens[i].blocked = false
if overlaps(sc, sc.tokens[i], w): sc.tokens[i].blocked = overlapsAny(sc, sc.tokens[i])
proc addWall*(sc: var Scene, w: Wall): int =
sc.walls.add w
@@ -152,8 +158,9 @@ proc removeWall*(sc: var Scene, id: int): bool =
proc updateWall*(sc: var Scene, id: int, w: Wall): bool =
## remove then add, id kept
if id < 0 or id >= sc.walls.len: return false
applyRemoved(sc, sc.walls[id])
let old = sc.walls[id]
sc.walls[id] = w
applyRemoved(sc, old) # remaining set includes the new wall; applyAdded then covers tokens only the new wall touches
applyAdded(sc, w)
true
+91 -21
View File
@@ -162,7 +162,7 @@ suite "move rules: player vs GM, step cap, uniform nack":
check s.moveToken(gm, 0, (200.0, 500.0)).kind == mkAck # onto the wall
check s.moveToken(gm, 0, (-1.0, 0.0)) == MoveResult(kind: mkNack, pos: (200.0, 500.0))
check s.moveToken(gm, 0, (5000.0, 0.0)).kind == mkNack
check s.tokens[0].blocked # GM moves never touch the flag
check s.tokens[0].blocked # ended on the wall: GM move set the flag
check s.moveToken(gm, 9, (1.0, 1.0)).kind == mkError
suite "blocked flag":
@@ -186,13 +186,13 @@ suite "blocked flag":
check not s.tokens[0].blocked
check s.setDoor(id, false)
check s.tokens[0].blocked
test "blocked token: player moves refused, GM move allowed and does not clear":
test "blocked token: player moves refused, GM move allowed":
var s = blockedSc()
discard s.addWall(W(110, 0, 110, 200))
check s.moveToken(me, 0, (40.0, 100.0)).kind == mkNack # would be a perfectly clear step
check s.tokens[0].pos == (100.0, 100.0)
check s.moveToken(gm, 0, (40.0, 100.0)).kind == mkAck
check s.tokens[0].blocked
check s.moveToken(gm, 0, (40.0, 100.0)).kind == mkAck # GM bypasses `blocked`
check not s.tokens[0].blocked # and landed clear of every wall: cleared
test "cleared by removing the wall; unrelated removals keep it":
var s = blockedSc()
let a = s.addWall(W(110, 0, 110, 200))
@@ -231,42 +231,112 @@ suite "blocked flag":
check s.updateWall(id, W(110, 0, 110, 200, door = true, open = true)) # became an open door: clears
check not s.tokens[0].blocked
check not s.updateWall(9, W(0, 0, 1, 1))
test "GM placement and GM move onto a wall never set blocked, and the token can escape":
test "GM placement and GM move onto a wall: blocked; player escape works only after a GM clear":
var s = scene(@[W(500, 0, 500, 1000)])
let i = s.addToken(tok(500, 400)) # placed exactly on the wall
check not s.tokens[i].blocked
check s.moveToken(me, i, (530.0, 400.0)).kind == mkAck # escape works (was the KNOWN LIMITATION)
check s.tokens[i].blocked
check s.moveToken(me, i, (530.0, 400.0)).kind == mkNack # stuck
s.gmClearBlocked(i)
check s.moveToken(me, i, (530.0, 400.0)).kind == mkAck # escape sideways
check s.moveToken(gm, i, (505.0, 400.0)).kind == mkAck # GM puts it back within r
check not s.tokens[i].blocked
check s.tokens[i].blocked
s.gmClearBlocked(i)
check s.moveToken(me, i, (505.0, 450.0)).kind == mkNack # still overlapped: refused
check s.moveToken(me, i, (540.0, 400.0)).kind == mkAck # but it can leave
test "Q14: a door closed 10 px from a token: token blocked, player refused, GM moves it, opening frees it":
test "Q14: a door closed 10 px from a token: token blocked, player refused, GM moves it clear, opening frees it":
var s = scene(@[], @[tok(110, 100)])
let id = s.addWall(W(100, 50, 100, 150, door = true, open = true))
check s.setDoor(id, false)
check s.tokens[0].blocked
check s.moveToken(me, 0, (140.0, 100.0)).kind == mkNack
check s.moveToken(gm, 0, (60.0, 100.0)).kind == mkAck # through the closed door
check s.tokens[0].blocked # GM moved it off the door; the bool flag cannot say which wall set it
check s.setDoor(id, true)
check s.tokens[0].blocked # GAP: opening clears only tokens still overlapping that door
s.gmClearBlocked(0)
check s.moveToken(gm, 0, (60.0, 100.0)).kind == mkAck # through the closed door, ends clear of every wall
check not s.tokens[0].blocked
check s.setDoor(id, false) # closing on nobody sets nothing
check s.setDoor(id, true) and s.setDoor(id, false) # closing on nobody sets nothing
check not s.tokens[0].blocked
s.tokens[0].pos = (110.0, 100.0)
check s.setDoor(id, true) and s.setDoor(id, false) # token back on the door: set again, then opening frees it
check s.setDoor(id, true) and s.setDoor(id, false) # token back on the door: set, then opening frees it
check s.tokens[0].blocked
check s.setDoor(id, true)
check not s.tokens[0].blocked
test "unconfirmed (b), pinned: opening a door clears blocked although another closed wall still overlaps":
test "doorway: token in an open doorway, door closes -> blocked, door opens -> free":
var s = scene(@[], @[tok(100, 100)])
discard s.addWall(W(110, 0, 110, 200)) # plain wall, overlaps
let id = s.addWall(W(100, 0, 100, 200, door = true)) # closed door, overlaps
let id = s.addWall(W(100, 50, 100, 150, door = true, open = true))
check not s.tokens[0].blocked
check s.setDoor(id, false)
check s.tokens[0].blocked
check s.moveToken(me, 0, (140.0, 100.0)).kind == mkNack
check s.setDoor(id, true)
check not s.tokens[0].blocked # literal Q14; DESIGN 5.5 lists this as unconfirmed
check s.moveToken(me, 0, (100.0, 150.0)).kind == mkNack # but the capsule still refuses an overlapped destination
check not s.tokens[0].blocked
check s.moveToken(me, 0, (140.0, 100.0)).kind == mkAck
test "KEEP: opening one door / removing one wall while another overlaps -> still blocked; last one frees":
var s = scene(@[], @[tok(100, 100)])
let a = s.addWall(W(110, 0, 110, 200))
let door = s.addWall(W(100, 0, 100, 200, door = true))
check s.tokens[0].blocked
check s.setDoor(door, true)
check s.tokens[0].blocked # plain wall still overlaps
check s.moveToken(me, 0, (40.0, 100.0)).kind == mkNack
check s.removeWall(a)
check not s.tokens[0].blocked
var t = scene(@[], @[tok(100, 100)])
let x = t.addWall(W(110, 0, 110, 200))
let y = t.addWall(W(90, 0, 90, 200))
check t.removeWall(y)
check t.tokens[0].blocked
check t.removeWall(x)
check not t.tokens[0].blocked
test "KEEP: wall update away from one of two overlapping walls keeps blocked":
var s = scene(@[], @[tok(100, 100)])
let a = s.addWall(W(110, 0, 110, 200))
let b = s.addWall(W(90, 0, 90, 200))
check s.updateWall(b, W(500, 0, 500, 200))
check s.tokens[0].blocked
check s.updateWall(a, W(500, 0, 500, 100))
check not s.tokens[0].blocked
test "GM moves a stuck token clear -> free; to another wall-overlapping spot -> still blocked":
var s = scene(@[W(110, 0, 110, 200), W(500, 0, 500, 200)], @[])
let i = s.addToken(tok(100, 100))
check s.tokens[i].blocked
check s.moveToken(gm, i, (505.0, 100.0)).kind == mkAck
check s.tokens[i].blocked # other wall overlaps
check s.moveToken(gm, i, (300.0, 100.0)).kind == mkAck
check not s.tokens[i].blocked
check s.moveToken(me, i, (330.0, 100.0)).kind == mkAck
test "GM drops a token inside a wall -> blocked; a door counts only while closed":
var s = scene(@[W(110, 0, 110, 200, door = true, open = true)], @[tok(300, 300), tok(100, 100)])
check not s.tokens[1].blocked
check s.moveToken(gm, 0, (100.0, 100.0)).kind == mkAck
check not s.tokens[0].blocked # open door: no wall
check s.setDoor(0, false)
check s.tokens[0].blocked and s.tokens[1].blocked
check s.setDoor(0, true)
check not s.tokens[0].blocked and not s.tokens[1].blocked
var t = scene(@[W(110, 0, 110, 200)], @[tok(300, 300)])
check t.moveToken(gm, 0, (100.0, 100.0)).kind == mkAck
check t.tokens[0].blocked
test "GM manual clear inside a wall: player escapes sideways, cannot cross":
var s = scene(@[W(500, 0, 500, 1000)], @[tok(500, 400)])
check s.moveToken(gm, 0, (505.0, 400.0)).kind == mkAck
check s.tokens[0].blocked
s.gmClearBlocked(0)
check not s.tokens[0].blocked
check s.moveToken(me, 0, (530.0, 400.0)).kind == mkAck # sideways out
var t = scene(@[W(500, 0, 500, 1000)], @[tok(505, 400)])
t.gmClearBlocked(0)
check t.moveToken(me, 0, (470.0, 400.0)).kind == mkNack # across the wall
check t.moveToken(me, 0, (510.0, 450.0)).kind == mkNack # destination still overlapping
test "an unrelated wall change elsewhere does not re-block a GM-cleared token":
var s = scene(@[W(110, 0, 110, 200)], @[tok(100, 100)])
s.tokens[0].blocked = true
s.gmClearBlocked(0)
let far = s.addWall(W(2000, 0, 2000, 200))
check not s.tokens[0].blocked
check s.updateWall(far, W(2100, 0, 2100, 200))
check s.removeWall(far)
check not s.tokens[0].blocked
let d = s.addWall(W(3000, 0, 3000, 200, door = true))
check s.setDoor(d, true) and s.setDoor(d, false)
check not s.tokens[0].blocked
suite "seed scene":
test "no escape hatch: a player cannot walk through any wall of a boxed room":
+1 -1
View File
@@ -57,7 +57,7 @@ suite "probing (T8)":
var empty = mkScene(@[])
var rnd = Rng(s: 99)
var dense = mkScene(randomWalls(rnd, 400, 3000))
dense.tokens[0].pos = (300.0, 2000.0) # may overlap a wall: not blocked, attacker cannot tell
dense.tokens[0].pos = (300.0, 2000.0) # may overlap a wall (unflagged, set directly): attacker cannot tell
var r = Rng(s: 5)
for i in 0 ..< 2000:
let a = r.uni(0, 2 * PI)
+5
View File
@@ -6,6 +6,7 @@
# d1/d2: drop arm 1/2 of the shared-vertex fixture
# e: cellsTouched without the fill spans | f: escape rule without the crossing check | g: GM moves checked against walls
# h: capsule reduced to centre path + destination circle (prototype H10) | i: no step cap | j: blocked trigger needs centre-on-wall
# k: wall removal / door open clears blocked unconditionally (no KEEP) | l: GM moves never set/clear blocked
# Log: results/mutation.log
cd "$(dirname "$0")/.." || exit 1
mkdir -p results
@@ -19,6 +20,8 @@ G="GM: ignores walls, step cap and blocked"
H="corner clipping|leg of the path|diagonal squeeze past"
I="step cap|over-cap, blocked-by-wall|P1:|P2:"
J="wall added within r of the circle|Q14: a door closed"
K="KEEP:|GM manual clear inside|Q14: a door closed"
L="GM moves a stuck token|GM drops a token|GM manual clear inside|GM: ignores walls"
rc=0
: > "$LOG"
run() { # $1 id $2 title $3 file to mutate $4 sed script ("" = control) $5 expected-failure regex
@@ -58,5 +61,7 @@ run g "GM moves checked against walls" server/moverules.nim 's/^ if not inBou
run h "capsule = centre path + destination circle (prototype)" server/moverules.nim 's/elif segsCross(s, d, w.a, w.b) or segSegDist(s, d, w.a, w.b) < r: return false/elif segsCross(s, d, w.a, w.b) or segDist(d, w.a, w.b) < r: return false/' "$H"
run i "no step cap" server/moverules.nim '/if hypot(dd.x, dd.y) > stepCap(sc, sc.tokens\[ti\]): return nack(s)/d' "$I"
run j "blocked trigger needs the centre on the wall" server/moverules.nim 's/segDist(t.pos, w.a, w.b) < sc.tokenRadius/segDist(t.pos, w.a, w.b) < 1e-9/' "$J"
run k "removal/open clears blocked unconditionally (no KEEP)" server/moverules.nim 's/sc.tokens\[i\].blocked = overlapsAny(sc, sc.tokens\[i\])/sc.tokens[i].blocked = false/' "$K"
run l "GM moves never set or clear blocked" server/moverules.nim '/^ if who.role == roleGM: sc.tokens\[ti\].blocked = /d' "$L"
echo "exit=$rc" | tee -a "$LOG"
exit $rc