Creating a riichi mahjong game, dilemma with dealing tiles and counting points.

I first asked this at UAsks, but after that I got directed to forum. I did quick search through forum and found some things that could help me but not quite (or maybe I just lack skills to utilize them as they are now. So sorry if I violate some rules or something, I just would like some discussion about this as it would probably help me with my project as an beginner developer.) Hopefully I am able to explain the situation clearly enough and I hope this is at right forum area.

Glad to be joining this community!

Following is just straight copypaste from UnityAsks.


Hello! I am creating a riichi mahjong game(japanese poker-style game) where point is to create a hand of four sets of three and a pair. I’m on a good start but I am having problem with randomizing tiles and calculating points. I’ve tried

var number = Random.Range

but don’t really know what to put in as value. (Game has three types of main tiles (1 through 9 of balls, bamboos and characters) as well as dragons (red, green and white) and winds (south, north, east and west) four of each (111122223333444455556666777788889999 Red dragon x4 White dragon x4 Green dragon x4 EastWind x4 WestWind x4 NorthWind x4 SouthWind x4) which in total comes as 136 tiles.

var number = Random.Range(1,137)

doesn’t seem to be what I am looking when pulling hands from the wall (tiles are shuffled and placed on 17 tiles wide walls that are 2 tiles high in front of every player and then depending on dealer are drawn from that four at time, but that’s not the point.) Any pointers on how I should approach my dilemma?

Then as my next problem comes the scoring system. To win, person first needs at least winning point in his hand. There is set amount of ways to achieve this. (reference Wikipedia: Japanese Mahjong Yaku)

Now, every winning hand is valued differently depending on if the person who gets it is dealer, how many winning points he or she has etcetera. I am struggling insanely with getting program to understand different winning hands adding points together and subtracting them is not a problem, but the way I should handle them. Should I just create a variable for every single possible winning hand there is (which is insane) or is there any more logical way to handle this?

Sorry for messy explanation and I hope you understand what I am looking for with this. For reference I suggest just looking for wikipedia about how points are distributed and stuff if I did not manage to explain them clearly enough in this.

Also, sorry for messy English, not my native language!

Thanks in advance everyone!

Well, i’m not saying this is the best solution but what i did with python some time ago was actually having and array like this :

allTiles [ 1m,1m,1m,1m … 4w,4w,4w,4w]

m = man zi tiles (characters)
s = sou zi tiles (bamboo)

w = wind tiles

That array contained every tile, then i would shuffle it and when i had to draw a tile i just did something like

drawTile()
return allTiles.pop()

So i gues you could do the same, have an array with all the available tiles, then shuffle them, like using another array and do something like

for( int i = 0 ; i < allTiles.Lenght ; i++)
{
    var random = Random.Range(1,137);
    newArray[random] = allTiles[i];
}

Obviously taking care of not repeating the positions that are already assigned.

Now you can start to check the winning hand with just a ToiToi hand since in my opinion it’s the easiest hand to check, or a ChiToiTsu hand.

Here is the code i used in python

def checkWin () :
	global pairs
	global sets

	if len( sets ) == 4 and len(pairs) == 1 :
		return True
	else :
		return False

The flow of my little program (i just had 1 hand and checked if it had won every update) was:

  1. Draw a tile ( as i said allTiles.pop() )
  2. Sort hand (here i had my hand array and checked how many triplets and pairs i had)
  3. Check if already won
  4. Cut a “useless” tile
  5. Repeat

Hope this helps and sorry but English is not my native language either.

I’m curious on how your progress is going on this game because I would love to do one myself as well.