Files
SirStone 9fcbe885c1 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).
2026-11-19 22:57:39 +01:00

29 lines
1.3 KiB
Nim

## shared test helpers (not a test file)
import std/[math, os]
import geometry
proc scaled*(n: int): int =
## FFF_MUTATION=1 (set only by tools/mutation.sh) divides random/oracle iteration counts by 10; normal runs use n.
if getEnv("FFF_MUTATION") != "": max(1, n div 10) else: n
proc W*(ax, ay, bx, by: float, door = false, open = false, sightDir = wdBoth): Wall =
Wall(a: (ax, ay), b: (bx, by), door: door, open: open, sightDir: sightDir)
proc box*(x0, y0, x1, y1: float): seq[Wall] =
@[W(x0, y0, x1, y0), W(x1, y0, x1, y1), W(x1, y1, x0, y1), W(x0, y1, x0, y0)]
# Tiny deterministic xorshift64 so tests do not depend on std/random version behaviour.
type Rng* = object
s*: uint64
proc next*(r: var Rng): uint64 =
r.s = r.s xor (r.s shl 13); r.s = r.s xor (r.s shr 7); r.s = r.s xor (r.s shl 17); r.s
proc uni*(r: var Rng, lo, hi: float): float = lo + (hi - lo) * float(r.next shr 11) / float(1'u64 shl 53)
proc randomWalls*(r: var Rng, n: int, span: float, x0 = 0.0): seq[Wall] =
## n random segments (length 10..300) with start in [x0, x0+span) x [0, span); every 7th is a door, every 14th open
for i in 0 ..< n:
let a: Vec = (x0 + r.uni(0, span), r.uni(0, span))
let ang = r.uni(0, 2 * PI)
let l = r.uni(10, 300)
result.add Wall(a: a, b: (a.x + l * cos ang, a.y + l * sin ang), door: i mod 7 == 0, open: i mod 14 == 0)