How do I randomly generate a dungeon with 4 different rooms to choose from?

Problem:
I’m trying to write a script that generates a random dungeon every time a button is clicked. I’ve spent multiple hours on it and got it to somewhat work. Most of the time it freezes or rooms intersect.
My Current Attempt at generations (Very pitiful)

There are four 4 types of rooms:

  • Intersection: This has 3 points where any room can connect

  • Hallway: This has 2 points for any room to connect

  • Hallway_WithDoor: This has 3 points for any room to connect

  • Room: This has 1 point for any room to connect

I created parts in each room titled “GENERATION PART” where other rooms can connect.

I’ve attached the world below if anyone would like to take a look. If I could just get this working maybe I could work on a seed system but right now I just want the map to generate randomly to a set number for each rooms. What would be the best way to approach this?
RNG_Generation_Attempt.rbxl (44.2 KB)

2 Likes

One way to make it easier is to make every room take up a cell in a rectangular grid. That makes it a bit easier to check if there’s a room in a spot so you avoid overlapping rooms. Here’s an approach that prevents overlaps, but doesn’t deal with dead ends so there are still openings

Dungeon Generator.rbxl (40.0 KB)

If you want to prevent openings, you should generate the tiles first and then place down rooms that fit with the number and positions of neighboring tiles afterwards.

4 Likes

Do you mean being able to generate the exact same map by using the same seed? Just set the seed of the RNG, if you’re using math.random do math.randomseed(da_seed) before generating the map, or if using the (new and improved) Random type just create a new RNG for before generating the map by calling Random.new(da_seed)

hi uhh i know its already 1 year late but, can u make it more customizable? and the rooms at will always be connect? thanks