This algorithm finds the optimal grouping for a mahjong hand. An optimal grouping minimises ungrouped tiles, then
minimises the number of pairs. The optimal grouping for a hand is not necessarily a winning one.
If the hand has 13 tiles, any tiles that could complete it are also shown.
Some special hands are also detected.
Loading... checker is 160KB, please be patient (if there is no change, try refreshing the page)
Enter hands as two-character suit-value pairs separated by spaces.
Suits are bamboo,
coins,
wanzi,
honours and
flowers.
Values are the digits 1-9, east,
south,
west,
north,
zhong,
fa and
ban.
Solved hands are shown in the order of pengs/pongs, chis/chows and pairs.
Interesting features like gang/kong or some other special hands are not implemented.
Notes for nerds:
Split splits your hand into sub-hands of the same suit before solving.
Memo controls memoization, turning it off will cause freezing on certain hands. Try it with 14 of the same tile. I
think all goroutines run on the main thread in js/wasm.
Check the console for call stats.
The wasm is compiled with tinygo, it maaaay be "wrong" compared to gc.
The strategies:
Optimal: Backtracking/DP solution using a slice to hold tiles at each subproblem.
Optimal Counter: Like Optimal, but uses a map of tiles to their counts. Lower branching factor, but higher memory use.
Greedy: Greedily builds 3-tile melds, then returns a solution if it can make a single pair with no tiles remaining.