maze
var
lowerBounds = null
upperBounds = null
list/area = null
turf/wallType = /turf/wall
turf/floorType = /turf/floor
New(turf/_lowerBounds, turf/_upperBounds)
lowerBounds = _lowerBounds
upperBounds = _upperBounds
area = block(lowerBounds, upperBounds)
proc
generate(seed)
if(!seed)
seed = world.realtime
else
rand_seed(seed)
generateMaze()
generateMaze()
var
list/unvisited = area
list/visited = list()
turf/currentCell = pick(unvisited)
unvisited -= currentCell
visited += currentCell
while(length(unvisited))
var
randomDirs = list(1, 2, 4, 8)
randomDir = pick(randomDirs)
turf/C = null
while(!length(randomDirs) ||\
!get_step(currentCell, randomDir) ||\
!(get_step(currentCell, randomDir) in area) ||\
(get_step(currentCell, randomDir) in visited))
randomDirs -= randomDir
if(length(randomDirs))
randomDir = pick(randomDirs)
else
break
if(!length(randomDirs))
currentCell = pick(visited - currentCell)
continue
C = get_step(currentCell, randomDir)
new/turf/floor(C)
currentCell = C
unvisited -= currentCell
visited += currentCell
It's basically the hunt-and-kill algorithm. It works, but the problem is that there aren't any actual walls in between the passages that are created. It's actually making a maze because if you put a delay in the main while loop you can see it putting the maze together, there's just nothing in between each passage. I don't really know how to fix this. Anyone have any experience in random maze generation that can help me? =/
I'm a bit hazy right now, so it's likely that I'm wrong... I'll take some time reading/debugging this later.