Bejeweled board generation

algorithm

Solution

One greedy approach would be during generating the board, every time you try to add a random jewel, just check if two previous ones horizontally and vertically are not the same to prevent the first situation (keep in mind the border conditions).

To ensure you have N number of matches, after you generate you can get a random point and update jewels either to the sides or top-bottom to make sure there are possible matches while still making sure the first situation won't happen.

Problem

I've recently stumbled upon this question: How would you generate a board for Bejeweled game to ensure that on the start there are no jewels that would collapse right away and that theres at least one possible move I've been thinking about doing it in random, letting them fall if they wish before we actually display the board and say that the probability of having no moves to make at all is very low so that we shouldn't worry about it. Is there a better approach?

Original source