- Main menu "Maze" button opens a setup panel (width, height in screens; complexity 1-5) and generates a maze of rock chambers joined by tubes, with Start and End pads and a win panel. - New one-way tube kind: orange tiles that only let the slime in at their entrance, with motes drifting into it (OneWayTube, TubeVacuum). The auto-tube trace moved to PixelStream.trace_tube so the player and the maze validator share it. - Generation: chamber graph (spanning tree rooted at End, one-way tubes only towards End on the route, extra tubes), carved with AStarGrid2D. MazeValidator re-derives the chamber graph from the tiles and checks that End is reachable from every chamber reachable from Start. - tests/maze_check.gd: headless batch check (360 mazes) plus a known soft-lock the validator must reject. See docs/MAZE.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
35 lines
1.3 KiB
GDScript
35 lines
1.3 KiB
GDScript
class_name MazeBuilder
|
|
extends RefCounted
|
|
|
|
# Makes a maze in a TileMapLayer: graph, then tiles, then the soft-lock check.
|
|
# A maze that fails (a tube couldn't be routed, or the check found a problem)
|
|
# is thrown away and the next seed tried. MazeLevel and tests/maze_check.gd
|
|
# use this.
|
|
|
|
const MAX_ATTEMPTS = 30
|
|
|
|
var isValid := false
|
|
var attempts := 0 # How many mazes it took (1 = the first one passed).
|
|
var usedSeed := 0
|
|
var carver: MazeCarver
|
|
var validator: MazeValidator
|
|
var problems: Array[String] = [] # Why each thrown-away maze failed.
|
|
|
|
|
|
func _init(layer: TileMapLayer, screens: Vector2i, complexity: int, firstSeed: int) -> void:
|
|
var level := MazeSettings.get_level(complexity)
|
|
for attempt in MAX_ATTEMPTS:
|
|
attempts = attempt + 1
|
|
usedSeed = firstSeed + attempt
|
|
var random := RandomNumberGenerator.new()
|
|
random.seed = usedSeed
|
|
var graph := MazeGraph.new(screens, level, random)
|
|
carver = MazeCarver.new(graph, screens, layer, random, level.winding)
|
|
if not carver.isComplete:
|
|
problems.append("seed %d: a tube couldn't be routed" % usedSeed)
|
|
continue
|
|
validator = MazeValidator.new(layer, carver.bounds, carver.startCell, carver.endCell)
|
|
if validator.isValid:
|
|
isValid = true
|
|
return
|
|
problems.append("seed %d: %s" % [usedSeed, validator.problem])
|