How can I reduce repetition of cells?

Hi friends, I have a problem in generating the world. The problem is that the world sometimes, so to speak, repeats the same thing and it turns out horribly and not beautifully, the generation works according to the dungeon principle (I did it from this video: How To: Make a randomly generated dungeon on roblox - YouTube).

I need to reduce the repetitions of a certain cell so that this is not the case:

but due to the fact that I am not very good at programming, I cannot write adequate code.


local rooms = game.ReplicatedStorage:WaitForChild("GeneratedRooms"):GetChildren()

for i, placeHolder in pairs(game.Workspace.PlaceHolders:GetChildren()) do
	local chosenRoom = rooms[math.random(3,#rooms)]:Clone();
	chosenRoom.PrimaryPart = chosenRoom.Floor;

	chosenRoom.Parent = game.Workspace;

What exactly do you mean by that? Do you want the next cell to not be the same as the last one or do you want it to be more compact in general?

For the first one you could use a table or a string (or whatever you can use to make them match in the code) to see if the last cell and the new one match or not.

For them to be more compact you could use a biomes logic, by making the children have inner children, each biome is randomly chosen and has a compact set of rooms.

1 Like

A good approach would be when you’re creating a cell, look at the cells you made before it. You can use the previous cells to calculate a probability of each cell type being next. For example, say you didn’t want lots of sand cells next to each other, you’d set the probability of the next cell being sand to a lower value if the previous cell was sand as well.

By changing the likelihood of a certain cell spawning after one of the same type does beforehand, you can sculpt the landscape while still maintaining randomness.


Okay, I’ll try your two options and see which one works best.

1 Like