## Adapters between the authoritative records (`world.SceneRec`, `tokens.TokenRec`) and the pure ## inputs of the vision code (`geometry.nim`) and the move rules (`moverules.nim`). No IO, no locks, ## no wire shapes: main.nim builds these per mutation and copies the outcome back. ## ## The two modules below exist because the walls and tokens are stored as records with wire fields ## (kind, open, flags, owner) while geometry and moverules take narrow value types. Keeping the ## translation in one place is what makes "the rules never see the wire" checkable. import std/options import geometry, moverules, tokens, world proc geometryWalls*(sc: SceneRec): seq[Wall] = ## The scene's walls as the vision code sees them: an open door does not block (5.1). result = newSeqOfCap[Wall](sc.walls.len) for w in sc.walls: result.add Wall(a: w.a, b: w.b, door: w.kind == wkDoor, open: w.open) proc moveScene*(sc: SceneRec, tokens: seq[TokenRec]): moverules.Scene = ## The scene as the move rules see it. One radius for every token in this slice: the per-token ## radius is #4's `token.resize` (slice 7), so the scene default stands in for all of them. result = moverules.Scene(w: sc.w, h: sc.h, tokenRadius: sc.tokenRadiusDefault, visionDefault: sc.visionRadiusDefault, walls: geometryWalls(sc)) result.tokens = newSeqOfCap[moverules.Token](tokens.len) for t in tokens: result.tokens.add moverules.Token(pos: t.pos, owner: t.owner, hasVision: t.hasVision, visionRadius: (if t.visionRadius.isSome: t.visionRadius.get else: 0.0), blocked: false, prev: t.prev, hasPrev: t.hasPrev) proc copyPosition*(tokens: var seq[TokenRec], ti: int, mr: moverules.Token) = ## Writes one token's position (and its door-push history) back after a rule ran. if ti < 0 or ti >= tokens.len: return tokens[ti].pos = mr.pos tokens[ti].prev = mr.prev tokens[ti].hasPrev = mr.hasPrev