Procedurally Generated Maze

Rllulium

New Member
Reaction score
10
Random dungeon? Funfunfun.

This is a little heavyweight at the moment, but I'd be delighted to get some feedback on how to improve it.
Note that the maze is being built with coordinates 0.0 as its lower left corner and that this is to be considered the starting point of the maze.
The destructable "Dungeon Gate" is being used for the walls.

JASS:
library DungeonStructs initializer OnInit

globals
    private constant integer HORIZONTAL = 'DTg1'
    private constant integer VERTICAL   = 'DTg3'
    private constant real    TILE_SIZE  = 512
    private constant integer MAX_SIZE   = 8
    
    tile array tiles
    integer tIndex = 0
    wall array vWalls
    integer vIndex = 0
    wall array hWalls
    integer hIndex = 0
endglobals

struct tile
    integer x
    integer y
    boolean flag
    
    static method create takes integer x, integer y returns thistype
        local thistype new = thistype.allocate()
        set new.x = x
        set new.y = y
        set new.flag = false
        return new
    endmethod
    
    static method setupAll takes nothing returns nothing
        local integer x = 0
        local integer y = 0
        loop
            set y = 0
            loop
                set tiles[tIndex] = tile.create(x, y)
                set tIndex = tIndex + 1
                set y = y + 1
                exitwhen y == MAX_SIZE
            endloop
            set x = x + 1
            exitwhen x == MAX_SIZE
        endloop
    endmethod
    
    static method resetAll takes nothing returns nothing
        if tIndex > 0 then
            loop
                set tIndex = tIndex - 1
                call tiles[tIndex].destroy()
                exitwhen tIndex == 0
            endloop
        endif
    endmethod
endstruct

struct wall
    integer x
    integer y
    boolean vertical
    boolean build
    destructable object
    
    static method create takes integer x, integer y, boolean vertical returns thistype
        local thistype new = thistype.allocate()
        set new.x = x
        set new.y = y
        set new.vertical = vertical
        set new.build = true
        return new
    endmethod
    
    method onDestroy takes nothing returns nothing
        call RemoveDestructable(object)
        set .object = null
    endmethod
    
    method generate takes nothing returns nothing
        if build then
            if .vertical then
                set .object = CreateDestructable(VERTICAL, x*TILE_SIZE, TILE_SIZE/2 + y*TILE_SIZE, 180, 0.8, 1)
            else
                set .object = CreateDestructable(HORIZONTAL, TILE_SIZE/2 + x*TILE_SIZE, y*TILE_SIZE, 270, 0.8, 1)
            endif
        endif
    endmethod
    
    static method generateAll takes nothing returns nothing
        local integer i = 0
        loop
            call hWalls<i>.generate()
            call vWalls<i>.generate()
            set i = i + 1
            exitwhen i &gt; hIndex
        endloop
    endmethod
    
    static method setupEdges takes nothing returns nothing
        local integer i = 0
        loop
            set vWalls[vIndex] = wall.create(MAX_SIZE, i, true)
            set vIndex = vIndex + 1
            set hWalls[hIndex] = wall.create(i, MAX_SIZE, false)
            set hIndex = hIndex + 1
            set i = i + 1
            exitwhen i == MAX_SIZE
        endloop
    endmethod
    
    static method setupAll takes nothing returns nothing
        local integer x = 0
        local integer y = 0
        loop
            set y = 0
            loop
                set vWalls[vIndex] = wall.create(x, y, true)
                set vIndex = vIndex + 1
                set hWalls[hIndex] = wall.create(x, y, false)
                set hIndex = hIndex + 1
                set y = y + 1
                exitwhen y == MAX_SIZE
            endloop
            set x = x + 1
            exitwhen x == MAX_SIZE
        endloop
        call .setupEdges()
    endmethod
    
    static method resetAll takes nothing returns nothing
        if hIndex &gt; 0 then
            loop
                set vIndex = vIndex - 1
                call vWalls[vIndex].destroy()
                set hIndex = hIndex - 1
                call hWalls[hIndex].destroy()
                exitwhen hIndex == 0
            endloop
        endif
    endmethod
endstruct

private function OnInit takes nothing returns nothing
    
endfunction

endlibrary</i></i>

JASS:
library DungeonGeneration initializer OnInit

globals
    private constant integer MAX_SIZE   = 8
    
    private integer array backtrack
    private integer bIndex
endglobals

private function DivideByEight takes integer i returns boolean
    local real r = I2R(i)/8
    local integer t = R2I(r)
    return r != t
endfunction
    
struct maze
    integer index
    boolean backtracking = false
    
    method checkValidity takes integer i returns boolean
        if i == 1 then
            return DivideByEight(index + 1)
        elseif i == 2 then
            return (index + MAX_SIZE) &lt; 64
        elseif i == 3 then
            return DivideByEight(index)
        elseif i == 4 then
            return (index - MAX_SIZE) &gt;= 0
        endif
        return false
    endmethod
    
    method checkFlag takes integer i returns boolean
        if i == 1 then
            return not tiles[index + 1].flag
        elseif i == 2 then
            return not tiles[index + MAX_SIZE].flag
        elseif i == 3 then
            return not tiles[index - 1].flag
        elseif i == 4 then
            return not tiles[index - MAX_SIZE].flag
        endif
        return false
    endmethod
    
    method GetSeed takes nothing returns integer
        local integer r = 0
        local integer i = 1
        local boolean break = false
        loop
            if checkValidity(i) and checkFlag(i) then
                set r = 1
            endif
            set i = i + 1
            exitwhen i &gt; 4
        endloop
        if r == 0 then
            return r
        endif
        loop
            set r = GetRandomInt(1, 4)
            if checkValidity(r) and checkFlag(r) then
                set break = true
            endif
            exitwhen break
        endloop
        return r
    endmethod
    
    method finish takes nothing returns nothing
        call stopPeriodic()
        call wall.generateAll()
        call BJDebugMsg(&quot;Done!&quot;)
    endmethod
    
    private method periodic takes nothing returns nothing
        local integer r = GetSeed()
        if not backtracking then
            set bIndex = bIndex + 1
            set backtrack[bIndex] = index
        endif
        set backtracking = false
        if r == 0 then
            set bIndex = bIndex - 1
            if bIndex &lt; 0 then
                call finish()
            else
                set index = backtrack[bIndex]
                set backtracking = true
            endif
        elseif r == 1 then
            set hWalls[index+1].build = false
            set index = index + 1
        elseif r == 2 then
            set vWalls[index+MAX_SIZE].build = false
            set index = index + MAX_SIZE
        elseif r == 3 then
            set hWalls[index].build = false
            set index = index - 1
        elseif r == 4 then
            set vWalls[index].build = false
            set index = index - MAX_SIZE
        endif
        set tiles[index].flag = true
    endmethod
    
    static method craft takes nothing returns nothing
        local maze new = maze.create()
        set new.index = 0
        set bIndex = -1
        call new.startPeriodic()
    endmethod
    
    implement T32x
endstruct

private function Check takes nothing returns boolean
    call tile.resetAll()
    call wall.resetAll()
    call tile.setupAll()
    call wall.setupAll()
    call maze.craft()
    return false
endfunction

private function OnInit takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterPlayerChatEvent(t, Player(0), &quot;new&quot;, true)
    call TriggerAddCondition(t, Condition(function Check))
endfunction

endlibrary

EDIT: To be honest, I did not know where to put this. It's not really a project, and I wasn't planning on submitting it. I guess this section is a good as any.
 

Magthridon96

Member
Reaction score
2
I tested it, and I must say, I'm quite impressed :)
Just a few things:
You don't need T32 for this. It could all be generated instantly.
If it hits the op limit, you could use trigger evaluations :)
In the GetSeed function:
JASS:
if r == 0 then
    return r
endif


You could change return r to return 0.
The speed difference is very marginal though, so you don't have to :p

Also:

JASS:
private function DivideByEight takes integer i returns boolean
    local real r = I2R(i)/8
    local integer t = R2I(r)
    return r != t
endfunction


Change this function to:

JASS:
function DB8 takes integer i returns boolean
    return i-(i/8)*8 != 0
endfunction
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
I tested it, and I must say, I'm quite impressed :)
Just a few things:
You don't need T32 for this. It could all be generated instantly.
If it hits the op limit, you could use trigger evaluations :)

no, you need to generate it over time, or you will screw players with low-end computers
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
people with low-end computers are the primary players of war3 >.>
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
>people with low-end computers are the primary players of war3 >.>
Haha I can't believe this, someone actually cares about performance of his map on old machines nowadays. People think if their map loads fast on their super computer and they don't notice any kind of performance reduction while playing for 2 hours that it is all good. But no. If it loads for more than a minute on an old 1.5 GHz 256 RAM computer then f$@% it. If your map happens to take more then 2/3 of the 256 RAM then it has some problems (and I'm not playing it =)). I guess 128 RAM goes for warcraft but the rest 42 RAM is all yours. I can't even play custom games anymore. Let me give you an example: LegionTDWar or something. This map ... this map has so many so many leaks that it's not playable even on a super computer. You need 1 of those TOP500 computers to play it and not get frustrated of it's spawing/leaking.
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
well, with such low RAM, a procedurally generated maze you're screwed no matter what haha

more on topic:
I find it interesting you've decided to surround solid cells with walls, rather then simply state is a cell is solid or empty and stick a giant block in it (which would be the roguelike approach)
 

Rllulium

New Member
Reaction score
10
Well, it all comes down with what I have to work with. The dungeon gate is alot better suited for this type of maze as opposed to the setup you were suggesting.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top