I made match-3 game and now i trying to add level generator. Now I generate level by filling random cells with random blocks, but I want to create generator which for given number of moves and number of block kinds generate level. What algorithms I can use if they exists?

  • 2
    \$\begingroup\$ My approch would be to start with the end game condition and undo random valid moves (i.e. add a block of 3, swap 2 tiles to make a block of 3 not a block of three etc.) \$\endgroup\$ Apr 25, 2012 at 9:39
  • \$\begingroup\$ @GeorgeDuckett is on to something, but puzzle modes in these kinds of games (where the object is to remove all the tiles) are normally better and more fun if the puzzle is generated by hand. (And to look like something) \$\endgroup\$
    – DampeS8N
    Apr 25, 2012 at 13:10
  • \$\begingroup\$ Can you clarify on the rules you use in your match-3 game? I'm slightly confused if by "given number of moves" you mean that with your ruleset the board is cleared entirely in some tetris-like manner, or if you want to ensure there's a maximum/minimum number of moves to execute on board in case it's bejewelled-like where new items are introduced from side of the screen to replace the void left by cleared pieces. Is your match-3 about switching two nearby items around or rotating many pieces in some more complicated manner like a square? \$\endgroup\$
    – Toni
    Apr 25, 2012 at 13:26
  • \$\begingroup\$ @GeorgeDuckett, I used such algorithm, but encounter with problem in answer of Darkwings. \$\endgroup\$
    – johnN
    Apr 25, 2012 at 14:48
  • \$\begingroup\$ @Toni, It's about switching two nearby items around. There is maximum number of moves/switches. No new items introduce from sides. \$\endgroup\$
    – johnN
    Apr 25, 2012 at 15:01

2 Answers 2


I'm assuming Match-3 is like Bejewelled, right?

I have no experience with this, but I would try the following:

  1. Generate random board
  2. Override some cells to create some 3 matches and maybe a 4 match
  3. Randomly move one of the cells in a valid way
  4. Make a few other random moves if necessary
  5. Validate by removing matches (if any) and replacing them

This doesn't give you any hard guarantees though. Experiment, I'd say :-)


Generating the blocks while the game is running, providing a good neighbors checking algorithm (depending on the difficulty level) would provide a less repetitive result.

Without a flexible algorithm a player will eventually memorize the pattern in a few tries. That's a possibility for any type of game depending of fixed patterns (even more complex games, like chess), and once it happens the trick gets old really fast.

This question is exactly about that concept: Connect-three game: Increasing level-of-difficulty as play progresses


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .