release ghosts from the pen via door target and staged exit

SPEC 01's four archetypes never left the ghost pen. With Pac-Man starting
below the pen, greedy Manhattan pursuit scores `up` as the worst option
from every cell inside, so the door is never chosen and all four ghosts
walk a closed loop forever. The bug predates SPEC 01: the original
`hunter` ghost was trapped too, and only the removed `random` ghost
escaped by luck, masking it.

Fixes it by aiming ghosts at the door while they are inside a PEN box,
then gating the release one ghost per GHOST_RELEASE_FRAMES.

The box deliberately includes row 12, the two door cells. Stopping at
row 13 would hand control back to the archetype while the ghost is
still in the doorway, and its target below would pull it back inside.

Measured on the first life with Pac-Man idle: the four ghosts clear PEN
at frames 51, 90, 160 and 240, all before the 300-frame criterion.
The release replays after a death because resetPositions zeroes
game.frame.

Implements SPEC 02 and closes the unmet acceptance criterion it leaves
in SPEC 01. The game stays deterministic; no randomness is introduced.
This commit is contained in:
luriasb
2026-10-18 01:12:38 -06:00
parent 90bc68449a
commit 66100a7b74
4 changed files with 192 additions and 3 deletions
+12 -1
View File
@@ -1,6 +1,6 @@
# SPEC 01 — Four distinct ghosts in the pen
> **Status:** Approved
> **Status:** Implemented
> **Depends on:** —
> **Date:** 2026-10-15
> **Objective:** Replace the current two ghosts with four ghosts that each follow a distinct behaviour, with Blinky chasing Pac-Man aggressively.
@@ -89,6 +89,17 @@ All four branches use the same `choices` filter and the same tie-break order (fi
- [ ] `decideGhost` in `src/js/game.js` has exactly four `kind` branches and no reference to `'hunter'` or `'random'`.
- [ ] On starting the game, four ghosts are visible inside the pen with colours red, cyan, pink, and orange (in that order in `GHOST_COLORS`).
- [ ] Within a few seconds of starting, all four ghosts have left the pen and are roaming the maze.
> **Not met by this spec alone, and not fixable within it.** Verified by simulating `maze.js` and
> `game.js`: with Pac-Man below the pen, greedy Manhattan pursuit scores `up` as the worst
> option from every cell inside, so no ghost ever takes the door. All four loop indefinitely.
> The risk table below wrongly assumes an available exit is eventually chosen.
>
> **Now satisfied via SPEC 02** (`specs/02-ghost-pen-release.md`, Implemented 2026-10-18),
> which targets the door while a ghost is inside `PEN` and staggers the release 60 frames
> apart. Measured on the first life with Pac-Man idle: all four ghosts clear `PEN` by frame
> 240, leaving at frames 51, 90, 160 and 240. The remaining criteria in this list are met
> by this spec.
- [ ] Túnel lateral in row 14 still wraps all four ghosts from one side to the other without getting stuck on the border.
- [ ] Pressing Start after `lost` or `won` resets the game to a fresh state with the four ghosts back at their start cells.
- [ ] No new files, no new dependencies, no ES module conversion, no build artefacts. Only `src/js/maze.js` and `src/js/game.js` change.