Help with random generation for match 3 game

I have been working on the cascading mechanics for my match 3 game and have settled on a standard linear drop as opposed to a delayed, EASING_INQUAD drop. Anyway, my issue is finding a balanced spawn system that does not generate so many of a single color instance. (Video attached)

My hope is there is a Match 3 pro among us that can assist a lowly dev. Right now I use a standard math.random()call. I googled and got an idea to use a buffered approach.

This would be a linear (or 2D) buffer of randomized tiles that are then run thru a Fisher-Yates shuffle and then each spawner plucks from the list upon request. The issue with this approach is my game has multiple spawners and some will use different spawned object list. I suppose I would have to create multiple list.

for example:

spawners =
	{
		{
			id = 0,
			{ spawn = "BLUE", probability = 1, board_max = 0, spawn_max = 0 },
			{ spawn = "GREEN", probability = 1, board_max = 0, spawn_max = 0 },
			{ spawn = "YELLOW", probability = 1, board_max = 0, spawn_max = 0 },
			{ spawn = "RED", probability = 1, board_max = 0, spawn_max = 0 }
		},
		{
			id = 1,
			{ spawn = "COIN", probability = 4, board_max = 0, spawn_max = 0 },
            { spawn = "BLUE", probability = 1, board_max = 0, spawn_max = 0 },
			{ spawn = "RED", probability = 1, board_max = 0, spawn_max = 0 }
		}
	}

Thanks for listening. Any advice would be greatly appreciated.

1 Like

Hi Jay_Cee, a couple of ideas that worked well for me in a similar setup:

1. Weighted pick instead of plain math.random(): use the probability values you already have in each spawner. Add up the probabilities, roll math.random() * total, then walk the list subtracting each entry’s probability until the roll drops below zero — that entry is the spawn. That alone stops one color from dominating when the weights are uneven.

2. Respect your caps: before picking, skip entries whose board_max or spawn_max is already reached (count what is on the board and what has spawned so far), and only roll among the rest. If everything is capped, fall back to the lowest-weight entry.

3. Avoid instant matches: when a tile spawns, check the two tiles below it (or to its left). If both are the same color as the pick, re-roll once or twice. This keeps the board from starting with clusters of one color.

Your shuffled-buffer idea also works — I would keep one buffer per spawner rather than one shared buffer, so each spawner keeps its own mix. Hope that helps, and good luck with the cascading mechanics!

1 Like

Thank you very much forbyour inut. Option 1 is one I did not think to implement. I will work on stress testing these options.

My current function is changing the way cascading and board refill happens.