I've been coming up with ideas for how I would go about programming a Bejeweled-like minigame. After some deep thought, I've managed to figure out how to detect matches (including special bonus cases like 4 in a row, 5 in a row, intersections...) without any real issue.
However, one major issue I'm struggling with is this: how do I detect possible moves, and influence the dispensing of new tiles in light of them?
Specifically, I need to be able to:
- Detect that there are no moves possible on the board
A legal move consists swapping two adjacent tiles in order to create a match of at least three in a row.
- Ensure that there are no moves on the starting board layout
This could be a simple case of "generate a board, check if there are any matches, try again until there aren't" but this seems messy.
- Ensure that there is at least one valid move on the starting board
Again, can be achieved by generating boards until true, but anything with more finesse than brute force would be nice.
- Optionally (based on game mode) ensure that tiles fall such that there is always at least one valid move on the board.
Once again, brute force simply says "pick some tiles to drop in, check there's a valid move, if there isn't then drop some different ones in until there is".
Ultimately almost all of these can be done through brute force, but I'm sure there must be a better way. At the core, however, I really need help with figuring out how to detect potential moves on the board...