I am supposed to make a game similar to Candy Crush in Java and I'm facing a possible issue.

At first I've thought of simply filling the grid with randomized values (from a specified interval) to represent different candies. For each level I am supposed to specify a value that would represent the number of available moves. However, with this completely randomized approach I'm not sure that I'll always have a feasible move. I haven't faced this in the game itself so I'm not sure how I should handle/solve this.

I would be very grateful if someone could tell me a possible solution!

Edit: Here is the code used to initialize the grid:

```
int x; //width of the grid
int y; //height of the grid
int candies;
int[][] grid = new int[x][y];
for (int i=0; i<x; i++)
for (int j=0; j<y; j++) {
int temp = (int)(Math.random()*(candies)+1);
grid[i][j] = temp;
}
```

editthis postto clarify what specifically you are seeking help with? Any algorithm to count the largest number of legal moves? An algorithm to always generate a solvable board? Something else? – chwarr yesterday