I'm looking for an algorithm that will determine if the current mahjong hand is a winning one. If you are not familiar with the game, here's the basic idea (simplified):
- There are three suits of tiles, each containing tiles ranked 1-9. There are also special tiles, seven types of them. Each tile exists in four copies, so there are 36 tiles of each suit and 28 special tiles.
- A hand has 14 tiles in it.
- A chow is a set of three tiles of a single suit with consecutive ranks.
- A pong is a set of three identical tiles.
- A kong is a set of four identical tiles.
- A pair is a set of two identical tiles.
- A winning hand is one in which the tiles form any number of chows, pongs, and/or kongs and one pair.
The hand is sorted by suit and then by rank. My idea is something like this:
- Mark all tiles as unvisited and nonwinning.
- Visit first unvisited tile.
- Check subsequent tiles until a chow, pong, or a kong is encountered, or until there is no possibility of it. If a combination is completed, mark all participating tiles as visited and winning
- If all tiles have been visited, check if all of them are winning. If not all tiles have been visited, go to 2.
The problem is that once a tile is a part of a combination is cannot be a member of any other combination, one that might make the hand a winning one.
Any ideas for a working algorithm?