- Home /
Errors in Procedurally Generated Dungeon
I am making a procedurally generated dungeon with rooms and pathways (for a roguelike). My GameController code is basically my whole game right now. It successfully generates the dungeon most of the time, but I have two errors, likely in the methods "UnifyDungeon" and "ConnectStuff":
1) ArgumentOutOfRange exception occurs about 25% of the time and breaks the program. I think I just have a bad line of code somewhere, this only started occurring today.
2) Algorithmic problem that always occurs but does not impede the program's function. Of course I would still like to fix it.
I explain my program below, but I am almost exactly following the steps on: http://journal.stuffwithstuff.com/2014/12/21/rooms-and-mazes/
Explanation of my program: DesignRooms -> PlacePaths -> ERRORS: UnifyDungeon -> PlaceGrid
DesignRooms: Generates a lot of randomly sized "rooms" then tries to place them on the map (stored as a 2D array of integers as "finalGridArray"). Successfully placed rooms get stored in "roomsFinalArray" list. This works fine.
PlacePaths: Uses Prim's algorithm to generate a maze structure in between the rooms. This also works fine.
ERRORS: UnifyDungeon: Goal is to place "doorways" so that all the rooms are reachable. This is where I am getting errors. I already have each tile of the map stored in "finalGridArray". I made a list of "Connector"s which are wall tiles between room/pathway or room/room. I assigned a room as the "merged" region into which I merge everything else. I pick a random Connector adjacent to the merged area, turn it into a doorway, then remove all the connectors connecting that same new room to the merged area. This step is generating the problems. Somehow I am not removing all of the connectors between the new room and the merged area. Then I add the new room to the merged area and repeat until all the rooms are in the merged area (and all the connectors should be gone). ConnectStuff is a function only used in UnifyDungeons and is likely where the problems are.
PlaceGrid: Places blocks on the game world using "floorGridArray" as the map. This works fine.
My project is here: https://www.dropbox.com/s/zpdwoops4imc73z/ProjectBuild.unitypackage?dl=0
I really appreciate any help you guys can give. I'm really stuck. I only took a short introductory CS class and am trying to learn more on my own so I apologize if my code is ugly. :)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Error CS0029: Cannot implicitly convert type to UnityEngine.UI.Transform 1 Answer
Filling area under linerenderer 2 Answers
[Solved]List.FindIndex error C# 1 Answer