The Tournament Framework for Mahjong

 

This page elaborates more materials of the paper published in ICGA Journal in March, 2014. This paper includes

l   the architecture of the tournament framework for Mahjong,

l   tile IDs,

l   environment settings of referee servers and

l   the format specification of communication protocol.

 

 


Architecture of the tournament framework for Mahjong

 

 

The framework for Mahjong tournaments is designed by leveraging an existing Mahjong network game system of a web game server, currently supported by ThinkNewIdea Ltd. The architecture of the system, as shown in the above figure, includes one Mahjong server and four clients, each for one player.

The framework for Mahjong tournaments is designed mainly by modifying clients into wrappers which invoke the corresponding AI programs. Thus, the framework includes one referee server and four wrappers for AI programs, as the gray boxes show in the above figure. The environment settings of referee servers are shown below. AI program designers only need to design the protocol between their AI programs and the framework (or the wrapper).

Initially, the referee of the tournament creates the referee server and sets up a seed which is used to generate all tiles of squared walls at random. Then the referee server waits for four AI players to login.

A client logs in to the referee server via the wrapper. The client needs to specify the client ID and the file path of the executable for the AI program. The client ID indicates the location of the Mahjong table as shown the above. The file path is used to let wrapper invoke the executable.

The AI program (the executable) can communicate with the referee server via the wrapper. In order to simplify the communication, the standard input of the AI program stands for the messages from the referee server to the AI program, while the standard output stands for those from the AI program to the referee server.

  


List of Tile IDs

 

List of Wan tiles.

 

1-Wan

2-Wan

3-Wan

4-Wan

5-Wan

6-Wan

7-Wan

8-Wan

9-Wan

Tile

萬1.png

萬2.png

萬3.png

萬4.png

萬5.png

萬6.png

萬7.png

萬8.png

萬9.png

TID

110-113

120-123

130-133

140-143

150-153

160-163

170-173

180-183

190-193

 

List of Tiao tiles.

 

1- Tiao

2- Tiao

3- Tiao

4- Tiao

5- Tiao

6- Tiao

7- Tiao

8- Tiao

9- Tiao

Tile

條1.png

條2.png

條3.png

條4.png

條5.png

條6.png

條7.png

條8.png

條9.png

TID

210-213

220-223

230-233

240-243

250-253

260-263

270-273

280-283

290-293

 

List of Tong tiles.

 

1-Tong

2-Tong

3-Tong

4-Tong

5-Tong

6-Tong

7-Tong

8-Tong

9-Tong

Tile

筒1.png

筒2.png

筒3.png

筒4.png

筒5.png

筒6.png

筒7.png

筒8.png

筒9.png

TID

310-313

320-323

330-333

340-343

350-353

360-363

370-373

380-383

390-393

 

List of Wind/Dragon tiles.

 

East

West

South

North

Red

Green

White

Tile

風東.png

風西.png

風南.png

風北.png

元中.png

元發.png

元白.png

TID

410-413

420-423

430-433

440-443

450-453

460-463

470-473

 

List of Flower tiles.

 

Spring

Summer

Autumn

Winter

Tile

TID

10

20

30

40

 

Plum

Orchid

Chrysanthemum

Bamboo

Tile

TID

50

60

70

80

 


Environment settings of referee servers

 

1.          Connect to this website http://140.113.210.162/gamev2/,  fill in the “Account” and “AIPath” field. “Account” will be your identity. “AIPath” is the absolute path of your AI program in your local disk. So the platform know where is your AI program.

 

If “AIPath” is filled, AI will be the operator. Otherwise, user is. “Account” and “AIPath” should be English. It’s forbidden that the same account appeared on the platform at same time, else both of them will be kicked by system.

 

You MUST filled in the field of “AIPath2”, “AIPath3” and AIPath4” as same as “AIPath”.

Login page

2.          It’s the digital signature warning. Just press “execute” button.

Security Certification

3.          And then you will enter the game lobby, select one of “training table” to start game.

Game Lobby

4.          Following is table setting. PAY ATTENTION! Set will be divided into two modes. An AI program mode is mainly used to test the correctness of the AI program, refer to point 5; another mode, four players can be AI program or human, please refer to point 6.

Table setting

5.          If the "Allow the computer to automatically pinch-hit" option ticked, the platform will open the table and call the AI program according to the AI program path filled out in step 1 as the other three players, as shown. Computer player at seat 2 is the AI program that path is field “AIPath2”, respectively.

Start game with three computer.

6.          If the "Allow the computer to automatically pinch-hit" option is NOT ticked, after opening the table, you must wait for the other three incoming human player, as shown below.

Waiting for other players

 

7.          The default setting is for human to play. If you want to let AI play, switch on the button at lower-right corner of the window before system deal cards. The platform will ask AI’s decision as your next move.

sPinch-hit by the computer



The format specification of communication protocol

 

The instruction formats from the referee server to clients

 

1.          /start MJ <position> <AIPath>

i. When game is starting, the referee server sends each client the instruction /start MJ to indicate the client ID and the file path of the executable of AI program.

ii. Actually, Field of <AIPath> is not necessary information.

 

e.g.  /start MJ 2 D:\AI _1.exe

In this case, the client ID is 2, its file path of the executable of AI program is “D:\AI_1.exe”.

 

2.          /initGame <wind> <game> <open> <dealer> <continue>

i. After the referee server send the instruction “/start MJ”, it broadcasts the instruction “/initGame” to each client to decide the client who is the dealer to start the game.

ii. <wind> and <game> indicate the current hand. Both of them will be one of EAST, SOUTHWESTNORTH, it is only affects the scoring of the game.

iii. <open> indicate which tile on the squared wall should be picked first, is only important in real world mahjong game.

iv. <dealer> is the client ID of dealer.

v. Consecutive-dealing, when the dealer wins the game or nobody wins the game (a draw game), the dealer will still serve as the dealer for the next game. <continue> is the times that the dealer consecutively be the dealer excluding the first time. But we disable this rule for fairness. So <continue> is always be 0.

 

e.g.  /initGame EAST EAST 3 2 0

it’s East Wind East hand, client number 3 is opener, client number2 is dealer, consecutively dealer times is 0.

 

3.          /initCard  <card1> <card2> … <card16> <card17>

i. The initial tiles player has, 17 tiles for the dealer and 16 tiles for others.

 

e.g. /initCard 121 122 142 143 152 220 241 260 270 342 351 370 383 390 462 463

means your AI get two 2-Wan, two 4-Wan, …, one green dragon. Remember when you want to discard a tile, you must discard the tile that matching one of your tiles with TID.

 

4.          /mo <card>

i. The referee sever sends client the instruction /mo that informs client of taking the tile with TID from the squared walls.

 

e.g. /mo 410

Taking the tile with TID 410 from the squared walls.

 

5.          /ask throw

i. The instruction /ask throw to inquire which tile to discard. It could happen after Mo, Eat, Pong.

 

6.          /ask pong

i. After someone discarded a tile, if a client is able to Pong, the server sends the client the instruction /ask pong to inquire whether to Pong or not.

 

7.          /ask gong

i. If a client is able to Meld Gong, Bu Gong or Covered Gong, the server sends the client the instruction /ask gong to inquire whether to Gong or not.

 

8.          /ask eat

i. After someone discarded a tile. If the next player is able to Eat, the server sends the next player the instruction /ask eat to inquire whether to Eat or not.

 

9.          /ask hu

i. If a client is able to make a winning pattern by Hu or Self Mo, the server sends the client the instruction /ask hu to inquire whether to Hu or not.

 

10.      /throw <position> <card>

i. After a client discarded a tile, server broadcasts the instruction /throw to indicate that the client discarded a tile to the pool.

 

e.g. /throw 3 410

Client number 3 throw the tile with TID 410.

 

11.      /eat <postion> <card1> <card2> <card 3>

i. After a client Eat, server broadcasts the message of Eat with tiles <card1> <card2> <card 3>.

ii. <position> is the ID of the client who Eat.

iii. The bidding tile is <card2>, number of <card1> less than number of <card3>

 

e.g. /eat 4 280 271 292

Client number 4 make a Shun with TID 280271292 by bidding the tile with 271.

 

12.      /pong <postion> <card1> <card2> <card3>

i. After a client Pong, server broadcasts the message of Pong with tiles <card1> <card2> <card 3>.

ii. <position> is the ID of the client who Pong.

iii. <card1> <card2> and <card3> is incremental series.

 

e.g. /pong 2 320 321 323

Client number 2 make a Ker of 3-Tong.

 

13.      /gong <postion> 4 <card1> <card2> <card 3> <card4>

i. After a client Meld Gong, server broadcasts the message of Gong with tiles <card1> <card2> <card 3> <card3> and client ID.

ii. <position> is the ID of the client who Meld Gong

iii. The third field 4 is Gong type, indicating Meld Gong.

iv. <card1> <card2> <card3> <card4> is incremental series.

 

e.g. /gong 2 4 160 161 162 163

Client number 2 Meld Gong 6-Wan.

 

14.      /gong <position> 0

/gong <position> 0 <card1> <card2> <card 3> <card4>

i. After a client make a Covered Gong, Server broadcast /gong <postion> 0.

ii. <position> is the ID of the client who Covered Gong.

iii. <card1>,<card2>,<card3> and <card4> is incremental series.

vi. Server send the one who make a Covered Gong the instruction with /gong <postion> 0 with tiles <card1> <card2> <card 3> <card4>, otherwise only broadcast /gong <position> 0.

 

15.      /gong <position> 1 <card>

i. After a client make a Promote-to-Gong, Server broadcast /gong <postion> 1 with a tile.

ii. <position> is the ID of the client who make a Promote-to-Gong.

iii. <card> is the tile that owner by AI.

 

e.g. /gong 1 1 154

Client number 1 upgrade Ker of 5-Wan to Gong of 5-Wan.

 

16.      /hu <postion> <hucard> <card1> <card2> …

i. When a client Hu or Self-Mo, server broadcast the instruction /hu.

ii. <position> is the ID of the client who Hu or Self-Mo.

iii. In case of Hu, <hucard> is the tile bid by winner. In case of Self-Mo, is the last tile Mo by winner.  <card1> <card2> … is the tiles of winner that still uncovered.

 

e.g. /hu 3 232 112 120 132 192 193 231 233 372 382 392 471 472 473

Client 3 Hu by bidding the tile with TID 232, and the tiles with TID 112, 120, 132, 192, 193, 231, 233, 372, 382, 392, 471, 472 and 473 was uncovered.

 

17.      /exit

/exit <score1> <score2> <score3> <score4>

i. Server ask AI for termination, and inform of the score in this hand.

ii. In normal situation, it will happen at the end game. But when server receive the wrong instruction, server will send the instruction /exit to AI for early termination and wake up default dummy AI to continue the game.

iii. <score1>, <score2>, <score3>, <score4> each for the score of client ID 1, 2, 3, 4 in this hand.

 

The instruction formats from clients to the referee server

 

1.          /throw <card>

i. After receive the instruction /ask throw from the referee server, AI discard the tile by sending the instruction /throw.

 

e.g. /throw 112

Client discard the tile with TID 112.

 

2.          /eat <card1> <card2>

i. After receive the instruction /ask eat from the referee server, AI eat the tile by sending the instruction /eat. 

ii. <card1> <card2> is the tiles that owner by AI and used to bid the tile from previous client.

 

e.g. /eat 132 145

AI bid the tile from previous client by using the tiles with TID 132 145.

 

3.          /pong <card1> <card2>

i. After receive the instruction /ask pong from the referee server, AI can Pong the tile by sending the instruction /pong.

ii. <card1><card2> is the tiles that owner by AI and used to bid the tile from one of other clients.

 

e.g. /pong 112 113

AI bid the tile from another client by using the tiles with TID 112, 113.

 

4.          /gong 4 <card1> <card2> <card3>

i. After receive the instruction /ask gong from the referee server in bidding time, AI can Meld Gong the tile by sending the instruction /gong 4.

ii. <card1> <card2> <card3> is the tiles that owner by AI and used to bid the tile from one of other clients.

iii. Cannot make a Gong by bidding the tile that discarded by previous player.

 

e.g. /gong 110 112 113

AI bid the tile from another client by using the tiles with TID 110, 112 and 113.

 

5.          /gong 0 <card1> <card2> <card3> <card4>

i. After receive the instruction /ask gong from the referee server, AI can make a Covered Gong by sending the instruction /gong 0 when it has four same tiles.

ii. <card1> <card2> <card3> <card4> is the tiles that owner by AI.

 

e.g. /gong 0 370 371 372 373

AI make a Covered Gong of 7-Tong.

 

6.          /gong 1 <card>

i. After receive the instruction /ask gong from the referee server, AI can make a Promote-to-Gong by sending the instruction /gong 1.

ii. <card> is the tile that owner by AI.

 

e.g. /gong 1 410

AI upgraded Ker of East Wind to Gong of East Wind by using the tile with TID 410.

 

7.          /hu

i. After receive the instruction /ask hu from the referee server, AI can Hu or Self-Mo by sending the instruction /hu.

 

8.          /pass

i. After receive the instruction /ask eat, /ask pong, /ask gong or /ask hu from the referee server, if AI want to do anything, then send the instruction /pass to server.