Real Life Mahjong Stat Analyzer [Python]

Real Life Mahjong Stat Analyzer [Python]


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!

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!):
  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:
  4. Read the readme file for further instruction.
  5. Open (with python.exe) and play, play, play. When you are done with all your games, open and input your club’s name, etc. You never need to open “mahjong.pyc”! Always run either or!

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.