A Bigger and Better Random Maze Generator

Post » Fri Feb 19, 2016 12:58 am

Hi all,


You know how mazes are only interesting the first few times, until you learn them, and then they end up being too small, and everyone says to just turn left or right continually to solve them? Mwahaha! So I wanted to make mazes that are too big and too varied to brute force. The player should want to use clues of some sort to get through in a reasonable amount of time. Like using torches on the walls at junctions, or boxes at dead ends with clues to turns, or being able to drop breadcrumbs ...


This maze path generating algorithm is pretty fast. My PC takes about 2 seconds to calculate a 32 x 32 path, but about a minute and a half to place the 1024 cells. There is an in-game menu to regenerate the maze and select the maze size, rng seed or not, branch length limit, forward step propensity, and the starting cell. It is hard to visualize the maze and it's easy to get coc'ed when trying to get a look at it using tcl, so I made a stairs up to an overlook to view it through the void. With the really big mazes, one can start the generation and then run up and watch it being placed as the path jumps around. There are 4 lonely floor sections in the void at the 4 corners just beyond the fartest extent that the largest maze can reach to prevent the player from getting coc'ed when running around in it.


It appears that this thing is basically useless, but it was fun to learn how to make. I learned alot, and my brain was getting fried from watching too many tutorials. It is a random maze generator made from nordic small hall sections. It only takes 5 sections to make the actual maze: a straight piece, a turn, a dead end, a 3-way junction, and a 4-way junction. Any recommedations for other libraries with those parts which would be well suited for mazes? Size is adjustable from 2 x 2 to 32 x 32 (length = width for convenience). It has big arrays in it. So if you like a whole lot of twisty passages all the same, this is for you. The start cell is along the north edge of the grid and the exit can be any cell along the east, west, or south edges. To make it more fun, the edge cell which is the farthest in steps from the start is being calculated as the maze exit. Then a hallway is added to connect the maze exit to a fixed external exit one row beyond the south edge externalExit cell. The external exit is indicated by a pillar behind a door to teleport the player back to the beginning. The fixed exit means it could be connected to and used in regular levels while still providing random mazes. But I haven't found anything to suggest it can have a navmesh. It was going to be alot more interesting with monsters in it. I did discover that bow guys will still stand there and shoot at me without a navmesh, but this maze is looking more like a lonely puzzle than a fight without one. Is there a way, like building and putting together pre-navmeshed pieces, to do it? Or has that been tried. I have seen something that looks like random selection of prebuilt rooms with mobs in them connected by random direction halls. Any comments, criticisms, or suggestions are mostly welcome.


This is another not ready for prime time dungeon with no mobs in it, so coc mazebuild1 to get into it. Too many things to learn. The esp file still has all my beginner stuff in it and I can't even see how to save it with another name and I have no idea how to try to remove stuff, LOL. If this effort is going to end here due to lack of interesting things to do with it, so be it. Now we know why nobody has made this before? However, I'm waiting for Fallout4's creation kit to see what they have done with navmeshes. With the new settlement building features, I'm hoping that the navmesh has been upgraded to scriptable. At least I wanted to get this out there for others to learn from and hopefully someone who knows what they are doing may find a good use for it. Please feel free to use anything or everything in it for any purpose. Here are the links to the esp from .../skyrim/data and the psc file from .../skyrim/data/scripts/source.


http://www.mediafire.com/download/91c7qkb9e2qj0i7/mazebuild02.psc


http://www.mediafire.com/download/c6c1c7vw1chchf7/testquest.esp


Here is the beginning the psc file for more details. It probably looks pretty similiar to the first maze generator:


Scriptname mazebuild02 extends ObjectReference

{randomly generate a maze from NorHallSm dungeon sections, with seed for repeatability}


int mazeWidth = 11 ; width (and length) of the maze in cells, range is 2 to 32

int startCell ; starting cell is any north(top) cell, but NOT CELL 0

; example with mazeWidth = 7, 7 x 7 grid of cells with id shown

; starting cell could be any from 1 to 6, exit is any cell on east, west or south edges


; North


; 0 1 2 3 4 5 6

; 7 8 9 10 11 12 13

; 14 15 16 17 18 19 20

; West 21 22 23 24 25 26 27 East

; 28 29 30 31 32 33 34

; 35 36 37 38 39 40 41

; 42 43 44 45 46 47 48


; South



; the path is a list of cells in the order they are discovered, negative => a junction

int pathIndex ; index of the path list

string pathStr = "" ; the path as a string of first 80 path cells

string pathState = "removed" ; initially no path through the maze


; Negative cells in the path are either (already found) junctions connecting new branches or

; forced dead ends due to the branch exceeding a length limit, which were later extended.

; Junction cells are found by retracing the path, from the beginning, using a follower cell.

; The follower's purpose is to check for unchosen cells along the path, and add junctions.

; The path jumps back to the follower cell at a dead end, or if limiting the branch length.

; The follower only moves to the next path cell when all adjacent cells are taken.

; Cell 0 can't be the entrance cell, and it can't be a junction with only 2 adjacent cells.

; The follower cell gets replaced by the next cell in the path if it doesn't have a junction.


float relativeForward = 0.5 ; 'relative' probability multiplier of a forward step in the path

; relative because it adjusts the probability compared to what would normally happen

; 1.0 => always choose to move forward, 0.0 => always choose to turn

; 0.5 is neutral: if 2 choices, relative = actual prob, if 3 choices, the actual prob is 1/3

; then relativeForward response: low slope below .5 (0 -> 1/3), higher slope above (1/3 -> 1)


int BranchLimit ; longest allowable branch length, set in-game

int branchLength ; if length > limit, treat as a dead end and jump back to the follower cell


int rngSeed = 1 ; defaults to a (sort-of) pseudo random number generator taking rngSeed

; if rngSeed = 0 set in-game, then Utility.RandomFloat(), different maze each time

int randm ; the RNG modulo output to be input to the next iteration

; string randmStr ; values of randm as a string


bool rngSeedCanChange = true ; default, true to get a repeatable sequence of seeds


int maxCellId ; mazeWidth * mazeWidth - 1 ; the cell with the largest id

int follower ; negative of startCell to denote the follower cell

int followIndex ; the path index of the follower cell

bool isFollowing ; true when searching for the next junction, current cell is negative

bool wasFollowing ; the value that isFollowing was at the previous path step

int prevCell ; for finding the current direction for forward step calc


; avail array begins as available for discovery indexed by cell id, length = 1024

; avail changed from availability to steps from the start upon path discovery of the cell

string availStr ; first 50 steps in the path from the start as a string

int juncDist ; junction cell distance from the start, for calculating steps from the start

; this makes "perfect" mazes with only one path from start to exit


; the edge cell with the most steps from the start is chosen for the exit cell

int farCell ; the edge cell that is the most number of steps from the start

int exitDir ; the maze exit direction which enters a hall leading to a fixed externalExit

; the hall from the random exit cell leads to the fixed last exit which has a return teleport

int externalExit ; the cell chosen/(calculated from startCell) for the fixed exit

; the actual external exit is one row (because of the hall) south of the externalExit cell

User avatar
james reed
 
Posts: 3371
Joined: Tue Sep 18, 2007 12:18 am

Return to V - Skyrim

cron