문제

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 rank in sequence.
  • 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:

  1. Mark all tiles as unvisited and nonwinning.
  2. Visit first unvisited tile.
  3. 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
  4. 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?

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top