2

I'm working on trying to identify a winning hand in mahjong, does anyone have any tips or a working formula?

The game of mahjong is like gin rummy with 13 cards, sets of 4,3 or flushes of 3. A winning hand includes the stolen or given card, which totals 14 cards. A winning hand is sets of:

  • 3 sets of 4 plus 1 pair
  • 4 sets of 3 plus 1 pair.
  • 2 sets of 4 plus 2 sets of 3, no pair.
  • Flushes are in sets of 3, but all one suite is a bonus.
  • All pairs is also an option.

There are also points associated with this.

Any guidance or help would be much appreciated. To follow up, and add info, this may help others, and gould help us to answer our own question,

I am aiming at Hong Kong Mahjong Rules. When I work through an algorithm, the one I am investigating is the removal of streets, and if fail, remove the set.

works when I have a b3333 b4 b5 b666
check b345 - remove
check b345 fail, b333 is a set, remove
check b678, fail, b666 is a set.
none left, Win

but when I have a b222 b33 b44 b5. I need to skip and restart. check b234 ok, remove check b234 ok, remove check b234 fail, single b2 (Failed hand) restart, skip 1. check b345 ok, remove end, return to start check b234 ok remove check b234 fail, b22 is pair. none left win.

but this method is troublesome, because there could be a double state to retry. b222 b33 b44 b555 b66 b77 check b234 ok, remove check b234 ok, remove check b234 fail, resart, skip 1. check b345 ok, remove check b345 ok, remove check b567 ok, remove check b678 fail, no 7, skip one rety

any ideas?
Alireza Fallah
  • 4,609
  • 3
  • 31
  • 57
Cyberience
  • 972
  • 10
  • 15
  • 1
    You should specify the target language(s) you want to do this in. Have you made attempts to develop a formula? Does it work? NO? Post it here ... that'll get more traction for you... – sdolgy Jun 24 '11 at 05:48
  • Are you sure you have the rules correct? The last time I checked the sets of 4 had special rules concerning the extra stones. But there are quite a few variants of this game, which one do you need? – LiKao Jun 24 '11 at 07:44
  • My Target is PHP, for the Engine which I am pretty efficient at. I haven't started on the code yet, till I can clearly define the rules to apply. The Extra stones are used for calculating the points, which is not related to a win, if you get the extra stone, you save it, and pull another. Again special hands handling I have a solution as they are quiet specific, the issue I have is to identify a win, Example is, 3 Chows, 123 234 345, if I check Sets of 3, I have 333, but then loos the 123 234 345, So I just want to find out if there is any good logic or existing script to follow. Thanks – Cyberience Jun 24 '11 at 09:01
  • I found this. http://homepage.mac.com/s_lott/books/python/html/p05/p05c05_mahjongg.html which seems to get pretty close, I will study it for a while, but still interested to know if there is any advise on the subject. – Cyberience Jun 24 '11 at 09:33

1 Answers1

1

I have implemented a successful mahjong game in Android. The algorithm I used was as follows:

1) Count the occurrence of each tile into an array of 34 2) Remove every possible pair 3) Recursively check the remaining tiles for triplets

Hope that helps

pvella
  • 190
  • 1
  • 9