Page 1 of 1
Maze level generator
Posted: Sun Apr 17, 2011 11:09 pm
by Freddybear
I have made a small modification to the maze level generator in game/engines/default/engine/generator/map/Maze.lua. This modification makes mazes with many short branches and lots of dead ends. They might be a little more "fun" to explore.
A diff file is attached.
Re: Maze level generator
Posted: Mon Apr 18, 2011 7:12 pm
by Freddybear
Second pass of the maze mod is complete. This version randomly changes the degree of branching in the generated maze.
The diff for this mod is [moved - corrected patch is below].
A screenshot of one maze level is here:

Re: Maze level generator
Posted: Mon Apr 18, 2011 8:19 pm
by Hedrachi
+1 Me likey... I don't particularly enjoy how in the default maze style you could explore for 50-75 tiles only to find that it's a big, long, confusing dead end, and spend the next 200 turns trying to remember which path leads back out again.
Re: Maze level generator
Posted: Mon Apr 18, 2011 8:38 pm
by lukep
A great step in the right direction, although I would like more variety still, some levels being labyrinths ( zero branches), some incorporating loops, and some exactly like this.
Re: Maze level generator
Posted: Mon Apr 18, 2011 11:42 pm
by Freddybear
I found a Lua error when the "pickp" variable was set to zero. This should fix it up.
One last edit (I hope).
Code: Select all
Index: game/engines/default/engine/generator/map/Maze.lua
===================================================================
--- game/engines/default/engine/generator/map/Maze.lua (revision 3238)
+++ game/engines/default/engine/generator/map/Maze.lua (working copy)
@@ -39,7 +39,12 @@
local xpos, ypos = 1, 1
local moves = {{xpos,ypos}}
+ local pickp = rng.range(1,4)
while #moves > 0 do
+ local pickn = #moves - math.floor((rng.range(1,100000)/100001)^pickp * #moves)
+ local pick = moves[pickn]
+ xpos = pick[1]
+ ypos = pick[2]
local dir = {}
if self.map(xpos+2, ypos, Map.TERRAIN) == self.wall and xpos+2>0 and xpos+2<self.map.w-1 then
dir[#dir+1] = 6
@@ -75,9 +80,7 @@
end
table.insert(moves, {xpos, ypos})
else
- local back = table.remove(moves)
- xpos = back[1]
- ypos = back[2]
+ local back = table.remove(moves,pickn)
end
end
-- Always starts at 1, 1
Re: Maze level generator
Posted: Tue Apr 19, 2011 2:46 pm
by marvalis
Looks like a good improvement, well done.
Re: Maze level generator
Posted: Tue Apr 19, 2011 6:40 pm
by darkgod
Thanks!