Post Reply 
(11C) Mahjong scores
11-14-2018, 08:47 PM (This post was last modified: 11-15-2018 09:12 AM by Rogier.)
Post: #1
(11C) Mahjong scores
Play and scoring characteristics:
Various variants of this game exist. This program was written to support score keeping according to the system I am used to.

Gameplay:
  • The players represent winds. When the game starts 1 = EAST, 2 = SOUTH, 3 = WEST, 4 = NORTH.
  • Each time someone other than EAST wins, the winds rotate counterclockwise. So if player 3 wins the first game, in the next game 1 = NORTH, 2 = EAST, 3 = SOUTH, 4 = WEST. And so on.

Scoring:
  • EAST pays and receives double points.
  • The winner pays nothing. The winner receives the number of points he/she scored from all other players. If EAST, the winner receives double points.
  • The other players receive their points scored from the other two. EAST pays and receives double.
  • When a games ends undecided no points are exchanged.

The program:
If you indicate who won and you input the scores for player 1, 2, 3 and 4, the program takes care of doubling for EAST and exchanging points between players. It also keeps track of the player who is EAST.

Notes:
Fitting this in the memory of an 11C proved tricky and my first efforts didn’t fit. In the end my brother in law worked out this system which I turned into a program with 9 lines to spare. It took us so long we didn’t have time left to play.
  • Each player receives 4 times the number of points he/she scored, unless EAST won, in which case he/she receives 3 times the number of points scored.
  • Each player pays the total number of points scored, except for the winner, who doesn’t pay at all, and EAST, who pays double


USE OF THE PROGRAM
  • Gsb 9: Starts new series of games, each player receives 10.000 points (lines 027-028, vary at will), player 1 = EAST, 2 = SOUTH, 3 = WEST, 4 = NORTH).
  • After each game:
    Indicate trough A / B / C / D who won. A = player 1 won, B = player 2 won, C = player 3 won, D = player 4 won. Then:
    1 > input points player 1 > r/s >
    2 > input points player 2 > r/s >
    3 > input points player 3 > r/s >
    4 > input points player 4 > r/s >
  • The calculator then displays 1 / 2 / 3 of 4 to indicate who is EAST in the following game
  • Do not do anything for games that end undecided!!


Code:

001    Lbl A    
002    5
003    GTO 0    
004    Lbl B
005    6
006    GTO 0    
007    Lbl C
008    7
009    GTO 0
010    Lbl D
011    8
012    GTO 0
013    Lbl 7
014    CF 0
015    Rcl I
016    x=y?
017    SF 0
018    0
019    F 0?
020    Rcl 0
021    Rcl 0
022    +
023    Rtn
024    Lbl 9
025    5
026    Sto I
027    EEX
028    4
029    Sto 1
030    Sto 2
031    Sto 3        
032    Sto 4
033    Rtn
034    Lbl 0
035    Sto 9
036    1
037    R/S
038    Sto 5
039    2
040    R/S
041    Sto 6
042    3
043    R/S
044    Sto 7
045    4
046    R/S
047    Sto 8
048    Rcl (i)
049    Sto + (i)
050    Rcl 5
051    Sto 0
052    3
053    Sto 5
054    Rcl 9
055    Rcl I
056    x=y?
057    GTO 2    
058    1
059    Sto + 5    
060    Lbl 2
061    Rcl 0
062    Rcl 5
063    *
064    Sto + 1    
065    Rcl 6
066    Sto + 0    
067    Rcl 5
068    *
069    Sto + 2    
070    Rcl 7
071    Sto + 0
072    Rcl 5
073    *
074    Sto + 3    
075    Rcl 8
076    Sto + 0    
077    Rcl 5
078    *
079    Sto + 4    
080    Rcl 9
081    5
082    x=y?
083    GTO 2    
084    GSB 7
085    Sto – 1    
086    Lbl 2
087    Rcl 9
088    6
089    x=y?
090    GTO 2
091    GSB 7
092    Sto – 2
093    Lbl 2
094    Rcl 9
095    7
096    x=y?
097    GTO 2
098    GSB 7
099    Sto – 3
100    Lbl 2
101    Rcl 9
102    8
103    x=y?
104    GTO 1
105    GSB 7
106    Sto – 4
107    Lbl 1
108    Rcl 9
109    Rcl I
110    x=y?
111    GTO 2
112    1
113    +
114    Sto I
115    8
116    x <=> y
117    x≤y?
118    GTO 2
119    5
120    Sto I
121    Lbl 2
122    4
123    –
124    Rtn


Used Registers:
I: EAST
R0: Total points scored
R1: Total player 1
R2: Total player 2
R3: Total player 3
R4: Total player 4
R5: Points scored by player 1 // replaced by 3 or 4 (muliplier for payments)
R6: Points scored by player 2
R7: Points scored by player 3
R8: Points scored by player 4
R9: Winner

Used Labels:
Lbl A: Player 1 wins
Lbl B: Player 2 wins
Lbl C: Player 3 wins
Lbl D: Player 4 wins
Lbl 0: Input points scored
Lbl 1: Determine EAST for next the game
Lbl 2: Simple jumps forward
Lbl 7: Calculates points to pay to each player
Lbl 9: Start new game

HP 33E, HP 11C, HP 48 SX, HP 35S
Find all posts by this user
Quote this message in a reply
11-15-2018, 03:24 PM (This post was last modified: 11-15-2018 09:07 PM by Albert Chan.)
Post: #2
RE: (11C) Mahjong scores
(11-14-2018 08:47 PM)Rogier Wrote:  Scoring:
  • EAST pays and receives double points.
  • The winner pays nothing. The winner receives the number of points he/she scored from all other players. If EAST, the winner receives double points.
  • The other players receive their points scored from the other two. EAST pays and receives double.
  • When a games ends undecided no points are exchanged.
  • Each player receives 4 times the number of points he/she scored, unless EAST won, in which case he/she receives 3 times the number of points scored.
  • Each player pays the total number of points scored, except for the winner, who doesn’t pay at all, and EAST, who pays double

I have not heard of this mahjong variant ... what is it ?

The scoring rules looks confusing.
Example: first rule, EAST pays (with what ? points ?) *and* receives double points ...

A worked out example might clear things up.
An example with EAST wins, another with other players win ...

When the game ended, does the whole pot, still added to 40 thousand points ?
If yes, the code only need to track 3 players ...
Find all posts by this user
Quote this message in a reply
11-15-2018, 09:47 PM (This post was last modified: 11-16-2018 10:28 PM by Rogier.)
Post: #3
RE: (11C) Mahjong scores
This is not the puzzle-style Mahjong. It's quite a complex game, with a lot of rules but it's fun. I will try and explain it in brief.

In this game the tiles are laid out in a square forming four walls 18 tiles long an 2 tiles high. By throwing dice the player who will be EAST for the first game is established and this player trhows dice to determine in which wall dealing will begin. The ' owner' of that wall throws dice te determine at which spot the dealing of tiles will begin.

Three players start out with 13 tiles, East starts out with 14. He will discard the fist tile. After that the players take turns drawing a tile. You may take a tile from the wall, but under circumstances you may also claim a discarded tile.
  • You may claim a discarded tile from any player to complete a pung (see below) or to win the game.
  • Under conditions, you may also claim a tile to complete a kong (see below).
  • A Tsjou (see blow) may only be completed by a tile discarded by your left-hand neigbour, or to win the game.
If you can't make a winning combination with the tile you took, you discard a tile of your choice (call it's name and place it on the table).

A winning combination is a combination of 14 tiles consisting of 4 triplets and 1 pair of identical tiles. If all players agree you can also accept other combinations as winning, like 7 "twins". Winning games have all sorts of beautiful Chinese names, which I don't know.
Triplets can be a combination of 3 identical tiles (like 3 times 3 bamboo) of 3 different tiles of the same colour and in ascending order (eg sign3-sign4-sign5). The first variety is called Pung, the second is called Tsjou. In some cases a Pung may be extended to a quadruplet, called Kong. In that case the player must take 1 extra tile from the wall (otherwise you can't win anymore).
If the tile completing a pung/kong was discarded by another player, the pung/kong is laid out on the table. Ifs the player took the tile from the stock, the tiles are kept hidden.
A tsjou scores no points, a kong scores double what a pung would do, hidden pungs and kongs score double points.

Example. WEST wins with this hand:
3X 7 of signs (in the hand)
3X 2 of signs (on table)
3X West wind (in the hand)
3X Red dragon (on the table)
2X North wind
The winning tile was North wind, discarded by another player

This would score:
2 points for the 2's of signs
4 points for the 7's of sings (hidden scores double)
4 points for the Red dragons (dragons and winds score double)
8 points for the West winds (hidden scores double)
Bonus for only way to win: 2 points
Bonus for winning: 20 points
Total so far: 40 points

This score is doubled for:
Pung of Red dragon: 1 (pungs and kongs of dragons do that)
Only one suit (so: no circles or bamboos) + honours (winds and dragons): 1
Pung of West wind: 1 (but only because our winner is WEST.)

So final score = 8x40 points = 320 points.

Now for the whole table:
EAST: 8 points
SOUTH: 20 points
WEST: 320 points (Winner)
NORTH: 64 points

Result (and this is what the program takes care of):
> SOUTH and NORTH pay WEST 320 points, EAST pays WEST 640 points
> SOUTH receives 2x(20-8) = 24 points from EAST
> SOUTH pays 64-20 = 44 points to NORTH
> EAST pays 2x(64-8) = 112 points to NORTH
EAST did not win, so the winds rotate. In the next game our winner will be SOUTH.

There are numerous game variants and various ways of scoring, but this is the system we use.
See also: https://en.m.wikipedia.org/wiki/Mahjong

BTW: you are right about the total points. It's a closed system, so knowing 3 players should be enough, but only for the 'grand totals'. Points scored per game is not a closed system. I found it easier to keep the values for all 4 players. If I want to check a ' credit status' I just Rcl 1-4. If I only kept score on 3 players I would need an extra piece of code to calculate the fourth.

HP 33E, HP 11C, HP 48 SX, HP 35S
Find all posts by this user
Quote this message in a reply
11-16-2018, 05:26 PM (This post was last modified: 11-17-2018 12:40 PM by Albert Chan.)
Post: #4
RE: (11C) Mahjong scores
(11-15-2018 09:47 PM)Rogier Wrote:  ... Now for the whole table:
EAST: 8 points
SOUTH: 20 points
WEST: 320 points (Winner)
NORTH: 64 points

Result (and this is what the program takes care of):
> SOUTH and NORTH pay WEST 320 points, EAST pays WEST 640 points
> SOUTH receives 2x(20-8) = 24 points from EAST
> SOUTH pays 64-20 = 44 points to NORTH
> EAST pays 2x(64-8) = 112 points to NORTH

Above cross exchange of points (from everyone) looks complicated.
Maybe it can be simplified a bit by removing EAST calculation.

players = {SOUTH, WEST, NORTH}
points = {20, 320, 64}

let c = sum(points) + 2*(EAST point) = 20 + 320 + 64 + 2*8 = 420
We use c to handle cross exchanges. Since WEST won, exchange = {c, 0, c}

scores = 4*points - exchange = 4 * {20, 320, 64} - {420, 0, 420} = {-340, +1280, -164}
EAST score = -sum(scores) = -(-340 + 1280 - 164) = -776

Can you provide an example where EAST win ?
My guess is, this should work (EAST win 6X his points): scores = 3*points - c
Find all posts by this user
Quote this message in a reply
11-16-2018, 10:26 PM (This post was last modified: 11-16-2018 10:56 PM by Rogier.)
Post: #5
RE: (11C) Mahjong scores
The cross-exchange is complicated. That' s why my first efforts didn't fit. It's just too cumbersome. The example is the way it's done by hand, the old fashioned way with chips of bone representing money.

The fastest way we came up with is:
  • Each player receives 4 times the number of points he/she scored, unless EAST won, in which case they each receive 3 times the number of points scored.
  • Each player pays the total number of points scored by all players, except for the winner, who doesn’t pay at all, and EAST, who pays double

Maybe your idea comes down to the same.

Now, presume in my example EAST wins:
EAST: 28 points (at least 20 more; bonus for winning. Let's keep it at that)
SOUTH: 20 points
WEST: 144 points (8*22 points less, because no bonuses for winning and winning tile)
NORTH: 64 points

Result:
> SOUTH, NORTH and WEST each pay 2x28= 56 points to EAST
> NORTH pays 144-64 = 80 points to WEST
> SOUTH pays 64-20 = 44 points to NORTH
> SOUTH pays 144-20 = 124 points to WEST
All in all:
> EAST gains 3x2x28 = 168 points
> SOUTH loses 56 + 44 +124 = 224 points
> WEST gains (124 + 80) - 56= 148 points
> NORTH loses 44 - (56 + 80) = 92 points
check: 168 + 148 - 224 - 92 = 0

HP 33E, HP 11C, HP 48 SX, HP 35S
Find all posts by this user
Quote this message in a reply
11-17-2018, 12:01 AM
Post: #6
RE: (11C) Mahjong scores
(11-16-2018 10:26 PM)Rogier Wrote:  Now, presume in my example EAST wins:
EAST: 28 points (at least 20 more; bonus for winning. Let's keep it at that)
SOUTH: 20 points
WEST: 144 points (8*22 points less, because no bonuses for winning and winning tile)
NORTH: 64 points
...
All in all:
> EAST gains 3x2x28 = 168 points
> SOUTH loses 56 + 44 +124 = 224 points
> WEST gains (124 + 80) - 56= 148 points
> NORTH loses 44 - (56 + 80) = 92 points

Thanks, Rogier

So, the guessed formula is correct: scores = 3*points - c
c = 20 + 144 + 64 + 2*28 = 284
EAST won, so scores = 3 * {20, 144, 64} - 284 = {-224, +148, -92}
EAST score = -(-224 + 148 - 92) = +168

My setup is almost the same as yours, except EAST score is derived from others.
This simplified coding, since EAST had very different rules than others.

Example: what if NORTH was the winner ?
scores = 4 * {20, 144, 64} - {284, 284, 0} = {-204, +292, +256}
EAST score = -(-204 + 292 + 256) = -344

WEST, not a winner, gain most points !
WEST, gain points no matter who win !!
Find all posts by this user
Quote this message in a reply
11-17-2018, 10:10 AM (This post was last modified: 11-17-2018 10:19 AM by Rogier.)
Post: #7
RE: (11C) Mahjong scores
Albert,

You are right. That is really interesting. Now the question is of course: will that lead to a more compact program? I'll give it a try.

BTW:
As my example shows you don't have to win to earn points. This leads tot 2 basic playing styles:
  • Try to get beautiful hands, which will lead to a lot of doublings and a high score. You won't always succeed, but if you do, you get a lot of points, often even if somebody else wins.
  • Just try and win as soon as possible with whatever tiles you can get. You won't earn as much, but every time you win, you get points and you don't pay a thing.
A third way is of course a mix of these two; if you have a reasonable chance of getting a hand with a lot of points > go for it. Otherwise > just try to win before someone else can score serious points.

HP 33E, HP 11C, HP 48 SX, HP 35S
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 5 Guest(s)