SlimePlatformer/docs/MAZE.md
tachyonwolf df89fa4ac7 Maze-book labyrinths, sucking one-way entrances, slime movement model
- Regions are now dense labyrinths (recursive backtracker on a coarse grid,
  1-3 tile corridors, braided loops by complexity); tubes run in the rock
  between regions, wall pipes give shortcuts inside a region.
- One-way entrances suck the slime in (player.pull_into_tube); blow zone
  is now 1 tile; blown motes are white. TubeBlower -> TubeAirCurrents.
- Validator: generous "might get to" areas vs strict SlimeMoves model
  (surface slides, corners, wraps, 1-tile gaps, ceiling falls, tubes,
  forced suction/blow tiles as all-outcomes states).
- maze_check: new hand-made blow-zone and suction traps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 16:15:23 -06:00

129 lines
6.9 KiB
Markdown

# Maze mode
A "Maze" button on the main menu asks for a size and a complexity, then
generates a puzzle-book labyrinth with tubes, a Start and an End.
## Goals (checkable)
1. Main menu has a **Maze** button. It opens a setup panel (same look as
Options) with **Width** (1-4 screens), **Height** (1-3 screens) and
**Complexity** (1-5), plus **Generate** and **Back**.
2. The same inputs and seed always give the same maze.
3. The maze fills `Width x Height` screens (one screen = 20 x 15 tiles, the
RoomCamera's room). Tubes run between screens and through walls.
4. **Maze-book feel:** each region is a labyrinth of narrow corridors with
1-tile walls: long winding paths, branches, dead ends. Complexity 1 is
roomy (3-tile corridors, many loops); 4-5 is a dense 1-tile labyrinth.
5. Tube kinds: auto, manual, goo (all kept) and **one-way** (orange tiles).
One-way tubes:
- only let the slime in at their entrance; orange motes drift into it;
- **suck**: the slime is pulled in as soon as its middle is on the tile in
front of the entrance, without pressing anything;
- **blow**: white motes stream out of the exit; within 1 tile of the exit
(the blow zone) the slime is knocked off a wall or ceiling, or lifted off
the floor (240 px/s away; sideways blows also lift at 120 px/s).
6. Start and End are clearly visible (green START pad, gold END pad).
Touching End shows a win panel with **New maze** and **Main menu**.
7. **No soft-locks.** From every place the slime might get to, End must still
be surely reachable. Checked on the finished tiles by a validator that
doesn't trust the generator; a failed maze is thrown away and the next seed
tried.
8. A headless check builds many mazes and runs the validator on each, plus
negative tests the validator must reject.
| Complexity | Regions per screen | Corridor width | Loops (braid) | One-way on route | Extra tubes / screen | Wall pipes / screen | Steered share |
|---|---|---|---|---|---|---|---|
| 1 | 2 x 1 | 3 | 50 % | 0 | 0 | 0 | 0 % |
| 2 | 2 x 1 | 2 | 30 % | 1 | 0.5 | 1 | 20 % |
| 3 | 2 x 1 | 2 | 15 % | 2 | 1 | 2 | 30 % |
| 4 | 1 x 1 | 1 | 5 % | 3 | 1 | 3 | 35 % |
| 5 | 1 x 1 | 1 | 0 % | 4 | 1.5 | 5 | 40 % |
## Non-goals
- No change to player movement, existing levels or other menus (besides the
one button). The player only gains what one-way tubes need: they only let it
in at the entrance, `pull_into_tube()` and `blow_away()`.
- No tube crossings or branching tube networks in mazes.
- No hazards, items or enemies. No saving of mazes; the seed isn't shown.
## Approaches considered (rework for maze-book layouts)
1. **Region graph + coarse-grid labyrinth per region (chosen).** Keep the
region graph (spanning tree rooted at End, one-way tubes towards End on the
route, extra tubes). Inside each region carve a classic recursive-backtracker
maze on a coarse grid (cell = corridor width, wall = 1 tile) and braid some
dead ends. Tubes between regions run in the rock between regions; short
"wall pipes" go through one wall inside a region as shortcuts.
Safe by construction: corridors are two-way, and the tree still leads to
End from every region. One-way ends only go where their forced tiles don't
cut a region (see `MazeTubeRouter`).
2. **Corridor graph with rooms.** Rooms joined by drawn corridors. More
varied shapes, but corridors cross and need their own routing, and it reads
less like a maze book.
3. **Tile-level random carving + full search.** Random walks/caves, keep if
the search passes. Little control over difficulty, many rejected tries.
Approach 1 gives the dense maze-book look directly, scales by corridor width
and braid, and keeps the old safety argument.
## How the slime moves (checked in the game)
A scripted run in 1-tile spaces showed the slime: crawls a 1-tall corridor's
floor and ceiling; gets from floor to ceiling there; climbs a 1-wide shaft up
and down; turns into a shaft above a corridor from the ceiling; falls into a
shaft below; and goes from a shaft back into a corridor. So the narrowest
corridor is 1 tile.
## The soft-lock check (`MazeValidator` + `SlimeMoves`)
Works only from the TileMapLayer, with two models:
- **Might get to (generous):** any air tile joined to Start's tile by air, or
through a tube it could go into.
- **Surely gets to End from (strict, `SlimeMoves`):** a state is the slime in
an air tile stuck to one solid side. Moves: slide along a surface, turn an
inside corner, wrap an outside corner, cross a 1-tile gap, let go of a
ceiling and fall, go into a tube mouth in the surface it's on (coming out
stuck to the exit mouth's face). Forced tiles: the tile in front of an
entrance (sucked in) and blow zones (blown to known spots: sideways onto the
landing tile's floor or the next; down, falling from the landing tile). A
state on a forced tile only counts if every place it can be moved to counts.
Exits that blow up, into a wall, sideways where it isn't 1 tile tall, or down
through another forced tile are rejected (their outcome isn't sure).
Pass if every state at every tile the slime might get to can surely reach End.
"Start reaches End" alone isn't enough: a one-way tube, a sucking entrance or a
blow zone can drop the slime where End is out of reach.
Not pinned: blow zones always have air past them and push the slime out of the
zone; suction only pulls into a tube that leads somewhere with room.
## Files
- `UI/maze_setup_menu.*` - the size/complexity panel.
- `Levels/Maze/maze_settings.gd` - inputs and the complexity table.
- `Levels/Maze/maze_graph.gd` - regions, spanning tree, one-way and extra tubes.
- `Levels/Maze/maze_corridors.gd` - carves a labyrinth into a region.
- `Levels/Maze/maze_tube_router.gd` - tubes between regions and wall pipes; one-way safety rules.
- `Levels/Maze/maze_carver.gd` - puts it together; Start and End.
- `Levels/Maze/maze_tiles.gd` - finds the tile for a tube shape and kind.
- `Levels/Maze/slime_moves.gd` - the strict movement model.
- `Levels/Maze/maze_validator.gd` - the soft-lock check.
- `Levels/Maze/maze_builder.gd` - graph, carve, check; next seed on failure.
- `Levels/Maze/maze_level.*`, `maze_marker.gd`, `maze_win_menu.*` - the playable scene.
- `Effects/one_way_tube.gd` - one-way rules: entrance check, exits, blow zones.
- `Effects/tube_air_currents.gd` - suction and blow acting on the player.
- `Effects/tube_airflow.gd` - orange motes in, white motes out.
- `Effects/pixel_stream.gd` - `trace_tube()`, shared by player and validator.
- `Assets/level_tiles.tres` - orange one-way tiles (alternatives 3-5) and their
custom data layers.
- `tests/maze_check.gd` - the headless check.
Run the check:
`godot --headless --audio-driver Dummy --script res://tests/maze_check.gd`
Negative tests: a one-way trap (a region whose only way in is a one-way
tube), Start in a blow zone, and two hand-made maps where Start and End are
joined by air (so an area-level check passes) but a blow zone or a sucking
entrance stops the slime.