(Underdepths) Pass 2

This commit is contained in:
AlexKucera committed 2026-08-12 18:44:04 +02:00
1 parent 6c2eef0019
commit b76eb550c9
37 files changed
+5590

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
Confirmed. Both failures are entirely outside my scope:
- **`can't set attribute`** → `engine/combat.py:79` does `defender.hp -= damage` on the test's immutable `namedtuple` Fighter — combat module bug, owned by others.
- **FOV/AI** → `engine.fov` and `ai.behaviors` modules don't exist yet — owned by others.
This matches the prompt's explicit note ("FOV/combat/AI owned by others may fail").
## Done — `engine/pathfinding.py` created
**A* gate results (mine):**
- ✅ `PASS: A*: path (2,2)->(17,17) len 31 through gap, contiguous`
- ✅ `PASS: A*: handles blocked/wall target without crashing`
- ✅ `python3 engine/pathfinding.py` self-check → `pathfinding self-check OK`
**Implementation highlights:**
- Exact signature: `astar(width, height, tiles, start, goal, blocked: frozenset = frozenset()) -> list[tuple[int,int]] | None`
- **Manhattan heuristic** (admissible + consistent for uniform 4-connected cost → first goal pop is a shortest path)
- **4-neighbour** moves, step cost 1
- walkable = in-bounds ∧ `tiles[y][x] == 1` ∧ not in `blocked`
- **Deterministic tie-break**: priority queue holds `(f, counter, x, y)` with a monotonic `counter` (FIFO among equal `f`, and `counter` guarantees heapq never compares `(x,y)`)
- **Lazy deletion** via a `closed` set so a node can be pushed multiple times cheaply
- Path returned **inclusive** `[start … goal]`; `None` when unreachable / out-of-bounds / un-walkable endpoints; `[start]` when `start == goal`
- **Pure / no mutation**: only local `g_score`, `came_from`, `closed`, `open_heap` are touched — inputs verified byte-for-byte unchanged in self-check #10
- No pygame, no third-party deps (only `heapq`)
- `__main__` self-check covers: optimal open-field length, contiguity/walkability, L-routes, `start==goal`, sealed-room `None`, single-gap threading, `blocked` closing the gap → `None`, determinism across repeated calls, out-of-bounds `None`, and input non-mutation.