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