Real Life Mahjong Stat Analyzer [Python]

2009y10m26d_211820156

Lately, some of us at IRC (the ones who didn’t know a thing about programming to begin with! most fellows are actually quite profficient at it) have started studying some Codecademy tracks, learned about different programming languages, datatypes, yaddayaddayadda.

What started off as a project of mine to build a hand score calculator for real life players who couldn’t score their own hands, has turned into a small program that keeps the score of your real life games at every one of its stages, saves the detailed results from every hand (and every game) into text files, then analyzes those results to give you detailed stats on every player!

[Read More for Download Link]

Because Chonbos actually happened.

The flow is pretty simple and every step is intuitive. You enter the players names, you select the winner, the type of win (who dealt in if it was ron), and the fan and fu of the hand.  You can tell the calculator if someone declared a riichi and that got taken by someone else, or if a drawn hand occurred. Even chonbo! Everything then is adjusted automatically.

It supports tenhou’s hanchan rules: 25k in, 30k out, 30k hill with West Round, Sudden Death and no North Round, (optional!) agariyame, tobi, and an uma 1-2 with oka. Though it is pretty easy to edit the source to use your own rules. For example, if you play with 30k in, 30k out with no oka, just edit the file that says “mahjong” and change 25000 for 30000.

As the games progress, it generates a txt file with the results of every hand.

At CAM, we play with 30k in 30k out.

There is also another text file with only the end results for clarity.

I plan to make an option to choose your own rules in the future with a list of variants, just in case. Most people play with this ruleset anyway.

After you have played a lot of games, you may then run the Analyzer. The Analyzer will go over every hand played by each of the players, and take a number of stats from them, making use of the format of the Hands text file.

The analyzer… analyzing.

This process only takes fractions of a second if you have only 8 players in your club like in the screenshot above.

It will print out a neat text file with a list of your player’s playing style and traits, their averages and other features, including stats for your club itself at the top! For example, our CAM club (Club Argentino de Mahjong):

The more games you play with this tool, the more accurate the reflected results will be.

How to install:

  1. Download the tool from Sourceforge (this is an open source project!):
    http://sourceforge.net/projects/mahjongstats/files/python_mahjong_scoreboardv9.zip/download
  2. Unzip all the files to the same folder. It is important that they are all there.
  3. This tool was written in Python 2.7, and thus runs in it. You need a Python interpreter (they are free!). If you are on a Mac or Unix system, chances are you already have it installed (though you must also tell your OS that the file is executable by using the command chmod +x filename). If you are on windows, I recommend you head to this page and select the appropriate version: http://www.python.org/getit/
  4. Read the readme file for further instruction.
  5. Open main.py (with python.exe) and play, play, play. When you are done with all your games, open analyzer.py and input your club’s name, etc. You never need to open “mahjong.pyc”! Always run either main.py or analyzer.py!

This can be considered an open beta of sorts. Find bugs, request features, and more importantly, if you are able to build a GUI for it, PLEASE DO! It would be much appreciated.

14 thoughts on “Real Life Mahjong Stat Analyzer [Python]

    1. Yeah. I wish I knew how to build a GUI. I was thinking of doing one with wxpython, Tinker or pygame (though this is not a game, pygame is very easy to use, and you can even add sound, menues, and so on and so forth).

      But it would be nice if someone else did it.

  1. Seems really sweet and complete, good job !
    I wrote on my own an app for Real Life Riichi MJ some time ago, which also calculates the hand points and keep tracks of the scores. A MacOS app and an Excel file for PC/Mac, available by clicking on my name (in french, sorry)

  2. I made an important update! Better download the tool once again:

    -Fixed a bug regarding conditions for West Round
    -Multiple Yakuman is now supported!
    -Fixed a bug regarding placing percentages.

    Coming soon:
    -Double Ron
    -A /real/ option for abortive draws (right now you have to just end the hand as a draw with everyone in tenpai)

      1. No updates on that. I have, however, created a github link, so people can help by editting it themselves. With limitted time, that is as much as I can do at the moment, I am sorry.

        I will work again on this whenever I learn how to make GUIs.

Leave a Reply

Your email address will not be published.