Strong Riichi Mahjong AI

Oct 19, 2023 | 5 minutes read
Share this:

A brief overview of Riichi Mahjong AI

Attempts to create a powerful artificial intelligence for the game of riichi mahjong have quite a long history.

First of all, we should mention the mjai project [1], a mahjong server written in Ruby, and the mjai-manue project [2], a mahjong AI based on Monte Carlo method. The mjai network protocol is used in many mahjong projects, including R Mahjong. It’s also worth mentioning the open source project mjai-occam. At that time, it was a fairly powerful AI, reaching a rating of over R1800 on Tenho [3],[4].

The pioneer who has developed truly powerful artificial intelligence for mahjong is Naoki Mizukami. Its AI was created based on Monte Carlo simulations and enemy models. Bakuuchi, created by Naoki Mizukami, reached the Phoenix Tenho lobby game level for the first time. Bakuchi was also the first powerful mahjong AI to be offered to the general public.

Later, more powerful AIs were developed for playing riichi mahjong. Among them, Super Phoenix and NAGA should be noted.

The Super Phoenix AI (Suphx) consists of five CNNs. Each model was first trained using supervised learning using replays of matches between top human players, and then refined using reinforcement learning based on self-play [5]. Suphx AI achieved a stable rating of 8.4 in Tenho. However, Suphx AI is not available for use by the general public. The NAGA AI has also reached a high level of play. A replay analysis service (paid) based on NAGA AI has been launched. It should be noted that these two AIs (Super Phoenix and NAGA) were developed by large companies.

In addition to mahjong AI developed by large companies, there are also mahjong AI developed by research institutes and independent developers. There are also open source projects.

One such open source project is Akochan [6]. Akochan uses multiple Markov decision processes (MDPs) as an abstraction of mahjong to construct efficient search trees [7]. When playing mahjong against 1 Bakuuchi and 2 manue, it has been shown that Akochan significantly outperforms Bakuuchi in terms of playing strength [7]. The disadvantage of Akochan is its slow speed.

The second open source AI project for mahjong that is worth mentioning is Mortal [8]. To train the model, Mortal uses both offline reinforcement learning (based on records of games played) and online reinforcement learning. Tests conducted by the author of the Mortal project have shown that Mortal far surpasses Akochan in terms of game play strength. Apparently, Mortal is currently the strongest AI for riichi mahjong. The Mortal project has a developed infrastructure that allows you to quickly conduct training and do many other interesting things. Thanks to the Akochan and Mortal projects, some problems that arose when training the SUO AI (AI for R Mahjong) have been resolved. There is also a free online service for analyzing games played on tenho and mahjongsoul (a free analogue of the NAGA service) based on Mortal and Akochan.

I will give my own (probably controversial) assessment of the strength of existing mahjong AI in a separate article. In my estimation, I can only say that ‘NAGA’ is significantly inferior to ‘Mortal’ in terms of strength.

Finally, we must mention kanachan [9], another interesting and ambitious open source project to create an AI for riichi mahjong. The kanachan project’s approach is to use huge amounts of data to train large models based on more powerful representation frameworks (Transformers). It is likely that this approach will indeed produce outstanding results. In this case, game recordings from Mahjong Soul are used (author kanachan has also written a library for downloading Mahjong Soul replays [10]). The goal of this project is to create a mahjong AI that can beat existing top-level AIs such as NAGA and Suphx, and even the best professional mahjong players. Unfortunately, the author does not provide any test results that would allow us to judge the achieved strength of kanachan AI.

Super Oracle(SUO)

Super Oracle (SUO) is an artificial intelligence for playing riichi mahjong. SUO is used in the riichi mahjong app “R Mahjong”. SUO uses machine learning to train a model that makes various mahjong decisions and then uses that model to make decisions. SUO uses CNN for five models (discard model, chi model, pon model, riichi model and kan model):

  • The Discard Model determines which tile must be discarded during a player’s turn.
  • The Riichi model determines whether Riichi should be declared.
  • The Chi model determines whether Chi should be declared and, if so, on which tiles.
  • The Pon model determines whether to declare Pon or not.
  • The Kan model determines whether kan should be declared.

The input of CNNs is the information observed by the player. The choice of input data structure has a significant impact on the prediction accuracy of the CNN. In SUO, except for the output layer size, all models ((Dahai model/Riichi model/Chi model/Pon model/Kang model) use similar network structure (Fig. 1).

mahjong models
Figure 1: Structure of Models

Each model contains 10 residual blocks, one input and one output CNN, and a dense layer at the output. Using these models, SUO makes decisions according to the flowchart in Fig. 2.

suo flowchart
Figure 2: Decision flow of SUO

Heuristics are used to make decisions, such as deciding whether or not to go all the way in the last game (to not go all the way, which would confirm last place). When training CNN, projects [6] and [8] were used.

A series of games were played to test the strength of SUO. Number of games played 3992 Games (Hanchan) 3 SUO vs 1 Akochan. The results are presented in Table 1.

Table 1: Result of 3992 Games (Hanchan)
Riichi Mahjong AI Average Ranking
Akochan 2.498
SUO 2.501