feat(walls): one-way sight per-viewer filter and ONEWAY fault (#58)
The vision fan blocks a sight-blocking one-way wall only for a viewer on its blind side (sight_dir names it; left is the (-dy,dx) normal of a->b), one sign test inline after the radius cull, so the hoisted wall list stays viewer-independent. Movement never reads the direction: one-way walls block both ways. Explored and tiles therefore differ by side and only ever grow. - geometry: WallDir + Wall.sightDir + blindTo, filter in visibilityPolygon. - worldmap: sight_dir mapping (movement mapping unchanged). - vision: the ONEWAY leak-fault build drops sight_dir player-side. - leakcheck: own side test for the fan and the clear-segment oracle; ONEWAY class detected against the sight_dir-dropped fan. - leak scenario gains a one-way wall the subject sees across; fault test asserts exactly ONEWAY. - oneway.test.mjs: both sides, tile sweep with its own oracle, flip with fixed endpoints, monotone explored/tiles, restart, two-way movement. - docs: DESIGN 5.8 mechanism sentence corrected; TESTING #58 markers built. - nginx harness: temp dirs created recursively (restart on one state dir).
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
## Fixed in M2 (DESIGN 5.5): token exactly on a wall can move off it (moverules escape rule); the move check is the
|
||||
## swept circle, not centre path + destination only; `moveBlocked` is gone from this module; cellsTouched is a scanline
|
||||
## (prototype per-cell version kept test-only in tests/refold.nim, differential-tested).
|
||||
## One-way sight (DESIGN 5.8, #58): `Wall.sightDir` names the blind side of `a -> b` (`left` = the `(-dy, dx)` normal)
|
||||
## and `visibilityPolygon` blocks such a wall only for a viewer on that side; the other side casts rays past it.
|
||||
## Movement never reads it: `moverules` gets the same wall and blocks both ways.
|
||||
## Known limitations (DESIGN 5.4 / 12):
|
||||
## - boundary epsilon ambiguity: RayEps 1e-4 rad, inclusive tests; token on a vision boundary is ambiguous
|
||||
## (leak checker and explored oracle use a 0.5 px neighbourhood).
|
||||
@@ -15,9 +18,19 @@ import std/[math, algorithm]
|
||||
|
||||
type
|
||||
Vec* = tuple[x, y: float]
|
||||
|
||||
WallDir* = enum
|
||||
## Which side of the drawn `a -> b` order cannot see across (DESIGN 5.8, #47/#58). `left` is
|
||||
## the `(-dy, dx)` side, the same formula as `position` (5.10) and the door-push side (5.5).
|
||||
## This is a sight-only field: movement is always two-way and never reads it.
|
||||
wdBoth = "both"
|
||||
wdLeft = "left"
|
||||
wdRight = "right"
|
||||
|
||||
Wall* = object
|
||||
a*, b*: Vec
|
||||
door*, open*: bool
|
||||
sightDir*: WallDir
|
||||
|
||||
const
|
||||
Eps* = 1e-9 # geometric tolerance (px)
|
||||
@@ -28,6 +41,19 @@ proc blocks*(w: Wall): bool = not (w.door and w.open)
|
||||
proc cross*(a, b: Vec): float = a.x * b.y - a.y * b.x
|
||||
proc `-`*(a, b: Vec): Vec = (a.x - b.x, a.y - b.y)
|
||||
|
||||
proc blindTo*(w: Wall, o: Vec): bool =
|
||||
## DESIGN 5.8: true when `o` stands on the side the wall's `sight_dir` names blind. One sign test
|
||||
## of the viewer against the `a -> b` left normal: cross(a->b, o - a) is the signed distance along
|
||||
## `(-dy, dx)`, so positive is the left side. A viewer exactly on the drawn line (|s| <= Eps) is
|
||||
## blind to either direction: the predicate is never ambiguous, even though the fan's own rays
|
||||
## start on the segment and a token standing on a wall already sees along it (5.5).
|
||||
if w.sightDir == wdBoth: return false
|
||||
let s = cross(w.b - w.a, o - w.a)
|
||||
case w.sightDir
|
||||
of wdBoth: false
|
||||
of wdLeft: s >= -Eps
|
||||
of wdRight: s <= Eps
|
||||
|
||||
proc rayHit(o, d: Vec, a, b: Vec): float =
|
||||
## smallest t > Eps where o + t*d hits segment ab (end-inclusive), else Inf
|
||||
let e = b - a
|
||||
@@ -54,6 +80,10 @@ proc visibilityPolygon*(o: Vec, walls: openArray[Wall], radius: float,
|
||||
# shortcut: walls beyond the circle are only culled by ray clipping, O(rays*walls); upgrade: spatial grid
|
||||
if max(w.a.x, w.b.x) < o.x - radius or min(w.a.x, w.b.x) > o.x + radius or
|
||||
max(w.a.y, w.b.y) < o.y - radius or min(w.a.y, w.b.y) > o.y + radius: continue
|
||||
# Per-viewer one-way filter (5.8, #58), inline and after the radius cull so the hoisted wall
|
||||
# list stays viewer-independent: a sight-blocking one-way wall blocks only a viewer on its
|
||||
# blind side; the other side sees across it. Two-way walls skip the test entirely.
|
||||
if w.sightDir != wdBoth and not w.blindTo(o): continue
|
||||
segs.add((w.a, w.b))
|
||||
for p in [w.a, w.b]:
|
||||
if abs(p.x - o.x) < Eps and abs(p.y - o.y) < Eps: continue # token on endpoint
|
||||
|
||||
+11
-3
@@ -5,7 +5,8 @@
|
||||
## Vision (5.1): one visibility polygon per token the player controls that carries the `vision` flag,
|
||||
## cast from the token centre against the scene's blocking walls with the token's range (Q7: the
|
||||
## token's `vision_radius` if it sets one, else the scene's `vision_radius_default`). Open doors do
|
||||
## not block; geometry.nim does the casting.
|
||||
## not block; geometry.nim does the casting. A sight-blocking one-way wall blocks only a viewer on
|
||||
## its blind side (the side `sight_dir` names), one sign test inline after the radius cull (#58).
|
||||
##
|
||||
## Explored (5.1, 8): the union of the cells every polygon ever overlapped, per player, strictly
|
||||
## per player (Q9 FIXED). It only grows: a wall edit or a door closing never un-explores. `cells`
|
||||
@@ -20,7 +21,7 @@
|
||||
## Change tracking: `ver` counts polygon changes (the client gets `vision` only when it changes, 6.4)
|
||||
## and `fresh` holds the cells this mutation added (4.2 step 8: cleared after egress).
|
||||
import std/[algorithm, math, sets]
|
||||
import tokens, worldmap, geometry, world
|
||||
import tokens, worldmap, geometry, world, faults
|
||||
|
||||
type
|
||||
Poly* = object
|
||||
@@ -48,8 +49,15 @@ proc cellOf*(sc: SceneRec, idx: int): (int, int) =
|
||||
|
||||
proc computePolys*(sc: SceneRec, tokens: seq[TokenRec], playerId: int): seq[Poly] =
|
||||
## One polygon per token of this player that has vision, in token order (a stable wire order).
|
||||
## The wall list is hoisted and viewer-independent: the one-way filter is inline in the ray fan
|
||||
## (geometry.visibilityPolygon), one sign test per one-way wall per viewer (5.8, #58).
|
||||
if playerId <= 0: return
|
||||
let walls = geometryWalls(sc, forSight = true)
|
||||
var walls = geometryWalls(sc, forSight = true)
|
||||
when defined(leakfault):
|
||||
# Negative control (DESIGN 10.3, TESTING 10.3): the ONEWAY fault drops `sight_dir` from the
|
||||
# player-facing computation, so a sight-blocking one-way wall blocks both sides.
|
||||
if faultActive("oneWay"):
|
||||
for w in walls.mitems: w.sightDir = wdBoth
|
||||
for t in tokens:
|
||||
if t.owner != playerId or not t.hasVision: continue
|
||||
result.add Poly(tokenId: t.id,
|
||||
|
||||
+4
-4
@@ -4,10 +4,10 @@
|
||||
##
|
||||
## Walls (DESIGN 8, FIXED #3): per-scene ids from `scene.next_wall_id`, monotonic and never reused
|
||||
## (a removal leaves the counter alone). Identity is `(scene, id)` in the DB, in memory and on the
|
||||
## wire. Today a wall's sight/movement behaviour is still `blocks = not (door and open)` in
|
||||
## geometry.Wall; the stored switches (`blocks_sight`, `blocks_movement`, `sight_dir`) gain their
|
||||
## behaviour in the window/one-way rounds (#57/#58). `flags` is a free JSON object the server never
|
||||
## interprets.
|
||||
## wire. A wall's sight/movement behaviour is still `blocks = not (door and open)` in
|
||||
## geometry.Wall plus the per-viewer one-way filter (`sight_dir`, #58); `blocks_sight` and
|
||||
## `blocks_movement` gain their general behaviour in the window/movement round (#57). `flags` is a
|
||||
## free JSON object the server never interprets.
|
||||
##
|
||||
## Wire payload shapes are DESIGN 6.1; the parts it leaves open are fixed here (recorded FIXED
|
||||
## owner-delegated, #19, in DESIGN 6.1/14):
|
||||
|
||||
+10
-3
@@ -18,18 +18,25 @@ import std/options
|
||||
import geometry, moverules, tokens, world, faults
|
||||
|
||||
proc geometryWalls*(sc: SceneRec, forSight = false): seq[Wall] =
|
||||
## The scene's walls as the vision code sees them: an open door does not block (5.1).
|
||||
## The scene's walls as the vision code sees them: an open door does not block (5.1), and a
|
||||
## one-way wall carries the side that is blind (5.8, #58). Movement gets the same mapping and
|
||||
## ignores `sightDir` (two-way).
|
||||
## `forSight` is only the sight computation; `LEAK_FAULT=secretgap` (a -d:leakfault build only)
|
||||
## opens a secret door there, the negative control for the door-equivalence group (#56).
|
||||
result = newSeqOfCap[Wall](sc.walls.len)
|
||||
for w in sc.walls:
|
||||
var wall = Wall(a: w.a, b: w.b, door: w.door, open: w.open)
|
||||
let dir = case w.sightDir
|
||||
of sdBoth: wdBoth
|
||||
of sdLeft: wdLeft
|
||||
of sdRight: wdRight
|
||||
var wall = Wall(a: w.a, b: w.b, door: w.door, open: w.open, sightDir: dir)
|
||||
if forSight and w.secret and faultActive("secretgap"):
|
||||
wall.open = true
|
||||
result.add wall
|
||||
|
||||
proc ruleWall*(w: WallRec): Wall =
|
||||
## The same wall as the move rules see it (they need `door`/`open` to know what blocks).
|
||||
## The same wall as the move rules see it (they need `door`/`open` to know what blocks; the
|
||||
## one-way direction is sight-only and never read by the move rules, so it is not mapped).
|
||||
Wall(a: w.a, b: w.b, door: w.door, open: w.open)
|
||||
|
||||
proc ruleToken*(sc: SceneRec, t: TokenRec): moverules.Token =
|
||||
|
||||
Reference in New Issue
Block a user