![random dungeon map generator algorithm random dungeon map generator algorithm](https://i.pinimg.com/originals/cf/27/da/cf27da2f081ee18a03a6d5959f349a57.png)
Setup: Create a 2D map of integers representing paths and initialize the entries to a "unprocessed" (not yet traversed) value, -1. I then check to see if all rooms are connected If they are not all connected I run a second algorithm that, in a non-sexy but definately good enough way in terms of dungeon layout, goes through the rooms and change them so that all end up being connected.Ĭhecking to see if all rooms are connected If the y-coordinate exceeds the dungeon height, we are done. If the x-coordinate exceeds the dungeon width, set the x-coordinate to 0 and advance the y-coordinate one step. Put down the room and advance the x-coordinate one step.Only need to check above and to the left due to step 2 below). Get a valid room type for the room (where valid room type is a type with no exits out of the dungeon and that have exits that matches the exits of the room above and the room to the left.Setup: Set the current room to the top left room. Rooms currently have no exits or exits in any 2, 3 or 4 directions.
![random dungeon map generator algorithm random dungeon map generator algorithm](https://bladecast.pro/images/bsp-dungen.png)
More important is that I, and others that read, may learn different ways to approach and solve the problem.īelow are my current implementation. Speed is not really a concern, but if speed can be gained at no real cost, well, that is a good thing. I am curious what other soltions may exist. The second make sure that all rooms are connected. The first generates the dungeon with its rooms. My current solution is that I run two algorithms. I am looking for better solutions than what I currently have. Problem to solve: Generate a random 2D dungeon map for a tile-based game where all rooms are connected.