The Concept
Instead of placing rooms randomly, we first design the flow of the level using a graph grammar. We start with a simple Start -> Goal connection and iteratively complicate it.
Rules: Replace a connection with a "Lock & Key" puzzle, or insert a "Monster" encounter.
Core Logic
// Graph Grammar Rule: Lock & Key
// Replaces: [A] -> [B]
// With: [A] -> [Key] -> [Lock] -> [B]
function addLockAndKey(edge) {
const keyNode = new Node("Key");
const lockNode = new Node("Lock");
graph.insert(edge, [keyNode, lockNode]);
}