Grid.* operates on the Map tilemap (Map.size/Map.row): a cell is passable unless
it is out of bounds or holds the caller's `wall` tile (a char code, e.g. '#'), so
any impassable glyph works. Everything is integer and deterministic.
- Grid.line(x0,y0,x1,y1) -> []Cell Bresenham line cells (LOS/raycast base)
- Grid.blocked(x,y,wall) -> bool the shared passability test
- Grid.line_of_sight(x0,y0,x1,y1,wall) unobstructed straight line?
- Grid.flood(x,y,wall) -> []Cell 4-connected reachable region (BFS)
- Grid.a_star(x0,y0,x1,y1,wall) -> []Cell shortest 4-connected path (A*,
Manhattan heuristic), empty if unreachable
The engine (runtime/native/grid.ludic, ~150 lines of Ludic, C-free) is spliced
into a game via core.ludic since it reads the tilemap runtime; returned Cell
slices are ordinary Ludic slices (`len` / `[i]`; each cell has `.x` `.y`).
Pathfinding lives under Grid rather than a `Path` namespace — that name is
already the filesystem-paths library (#10).
Verified against Python references: a 1500-case fuzzer over random maps agrees
exactly on A* path length (optimal, == BFS), flood-fill count, and line-of-sight.
examples/library/grid.ludic asserts the behaviour and is wired into `x test`
(now 61 passed); docs: a Grid section + 5 per-symbol pages, inventory/coverage
green. Seed reseeded; the C-free bootstrap fixpoint holds.
Scope: this lands the Grid.*/pathfinding half of #24. The ECS Query.* helpers
(count/first, and nearest/within which want a runtime spatial index) remain the
tracked follow-up the issue calls out as blocked.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
27 lines
722 B
Markdown
27 lines
722 B
Markdown
---
|
|
id: grid-flood
|
|
name: Grid.flood
|
|
category: grid
|
|
kind: namespace-method
|
|
tokens: Grid.flood
|
|
sig: Grid.flood(x, y, wall) -> []Cell
|
|
tip: Every passable cell reachable from (x,y), 4-connected, in BFS order.
|
|
order: 4
|
|
ns: Grid
|
|
member: flood
|
|
---
|
|
|
|
Returns every passable cell reachable from <code>(x, y)</code> by 4-connected steps (up/down/left/right over non-<code>wall</code> cells), in breadth-first order — for connectivity checks, filling a room, or measuring an enclosed area. Empty if the start itself is blocked.
|
|
|
|
Parameters:
|
|
- `x`, `y` — the seed cell
|
|
- `wall` — the impassable tile char
|
|
|
|
```ludic
|
|
program Demo {
|
|
handler H phase Update {
|
|
let region = Grid.flood(2, 2, '#')
|
|
print(len(region))
|
|
}
|
|
}
|
|
```
|