Open GeJ opened 9 years ago
IIRC -- and you know this was a looooong time ago, so my memory escapes me, I believe the hardest part is just detecting the Agari. Yaku can be detected using heuristics, as there aren't that many of them -- it also depends on the local rule too. For example, some people play with the rule that you can't finish with 食いタン, but there are local rules that allows this too.
So the processing would need to be something like
if ($hand->is_agari()) { # what you wrote
if ($hand->meets_local_rule_criteria($rule) ) { # heuristics based check
$score = $hand->calculate_score($rule); # this is probably the easy part
}
}
I took the link in the TODO page : http://hp.vector.co.jp/authors/VA046927/mjscore/mjalgorism.html
At the bottom of the article, one link points to a ruby script that generate a mapping of all the winning hands using the author's encoding. Also, another link points to a Java class that implements winning hand detection using the author's algorithm.
I made a quick porting of the Java part, available here :
https://gist.github.com/GeJ/d7b907dcb0c30298d993
The algorithm seems indeed really fast to figure out if a hand is a winning hand or not. From what I understand, it works like this :
For a close hand, that's really useful, however if a chi or pon have already been called, you have no way to indicate them in the input. The best way will be to test the raw 14 tiles, and from the result, see if your open mentsu match the ones the algorithm found.
Also, contrary to what I understood on FB, the algorithm doesn't do Yaku detection (or maybe were you talking about another algorithm than the one in the TODO file?).
Should I try to incorporate the algorithm in Acme::Mahjong and send you a PR?