Algorithm to find streets and same kind in a hand

前端 未结 3 1603
有刺的猬
有刺的猬 2020-12-15 23:16

This is actually a Mahjong-based question, but a Romme- or even Poker-based background will also easily suffice to understand.

In Mahjong 14 tiles (tiles are like ca

3条回答
  •  没有蜡笔的小新
    2020-12-16 00:04

    I would break it down into 2 steps.

    1. Figure out possible combinations. I think exhaustive checking is feasible with these numbers. The result of this step is a list of combinations, where each combination has a type (set, street, or pair) and a pattern with the cards used (could be a bitmap).
    2. With the previous information, determine possible collections of combinations. This is where a bitmap would come in handy. Using bitwise operators, you could see overlaps in usage of the same tile for different combinators.

    You could also do a step 1.5 where you just check to see if enough of each type is available. This step and step 2 would be where you would be able to create a general algorithm. The first step would be the same for all numbers of tiles and possible combinations quickly.

提交回复
热议问题