Giter Site home page Giter Site logo

ledenel / auto-white-reimu Goto Github PK

View Code? Open in Web Editor NEW
9.0 1.0 1.0 416 KB

a mahjong library aimed to implement mahjong AIs by imitating white reimu -- a excellent mahjong player.

License: GNU General Public License v3.0

Python 94.31% HTML 3.81% Batchfile 0.06% Shell 1.81%
tenhou mahjong mahjong-algorithm

auto-white-reimu's People

Contributors

canuse avatar lance6716 avatar ledenel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

canuse

auto-white-reimu's Issues

estimate win rate (pure theoretical by math computations)

Since here we could get all possible combination for win:

def _win_selections_in_tiles(self, hand: TileSet, ignore_4counts, current_state: WinPattern,

assume each invisible tile is equal probability, we could leverage multinomial distribution for given a possible combination with r tiles in the invisible set:

like wikipedia explained,
we could directly get all possible combinition probability just simply sum the pmf of each combination
here.

Error in from_file function

Function from_file(file) in mahjong.record.reader.py will cause a TypeError at mahjong.record.reader.py, line 117 when passing the filename into the function.

paifu analyze demo: infer ranking based on score

Something like:
Given current score, game round, is oya, seat order, output ranking possibility like:

top: 6%
second: 30%
third: 60%
last: 4%

means that you may most probably get third ranking, and almost safe from being last, and has substantial chance to beat second player down, from given situations. Tenhou Pt estimation is also possible.

Fail to parse some tenhou records.

When parsing some files using from_file, an xml'Namespace' object has no attribute 'n0' (sometimes n1) error occured:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\canuse\PycharmProjects\auto-white-reimu\mahjong\record\reader.py", line 187, in from_file
    return TenhouRecord(next(ET.parse(file).iter()))
  File "C:\Users\canuse\PycharmProjects\auto-white-reimu\mahjong\record\reader.py", line 140, in __init__
    [meta.UN.n0, meta.UN.n1, meta.UN.n2, meta.UN.n3],
AttributeError: 'Namespace' object has no attribute 'n1'

A total of 18469 file was processed and this error occured 98 times ( with 'n0' 83 times and 'n1' 15 times)

For example,
2019010115gm-00a9-0000-21b95613.xml raised an 'n1' error and 2019010202gm-00a9-0000-3142addc.xml raised an 'n0' error
2019010115gm-00a9-0000-21b95613.zip
2019010202gm-00a9-0000-3142addc.zip

Notes on learning how to contribute to this project

Here's TODOs collected from comments below:

  • Add class doc to give brief explanation, in order to make new developer easier to understand.

  • Tile._hash and Tile._tuple_view seems duplicated, check if should keep only one of them.

  • Add win pattern of Thirteen Orphans(国士無双)

  • Add input-check about the number of tiles, input grammar and same tile overflow.

  • Add matching for yaku(役) and score calculation

  • Add continus integration and cover all codes with unit test

  • Add documentation for Tile, TileSet Waiting WinPattern and merge duplicate search algorithms for easily read and use.

  • Add safe tiles calculations based on remain waiting forms counting(i.e. how many 68s, 56s, 89s, 7s could waiting for 7s without furiten(振听)).

  • Add zh-CN and en-US documentation support.

  • checked: TileSet.re_sort() should be called to keep insert order invariant.

  • checked: class Tile and TileSet use @total_ordering, according to official doc, should evaluate if it's the bottleneck of the performance.

Very useful and a good change to learn Python, thanks owner.

Now I'm reading the source code, here I wrote potential development.

Misidentifying players with the same ID in one game

Log: http://tenhou.net/0/?log=2019022817gm-0011-5574-e1a854ec&tw=1
The game log above contains three different players with the same ID 'NoName'. The script ought to provide three different reasoning reports corresponding to each of the players when running "check result for all players", but it misidentifies the first player three times and only provides one report instead. (actually it overwrites the same output file for three times)
Numbering the IDs or attach the seat order to the ID might be needed.

paifu analysis plan

This issue collects all things about paifu analysis, including:

  • universal paifu representation, manipulation and serialization. for example, support tenhou.net/majsoul/tziakcha.xyz paifu reading and convert.
  • paifu analysis alogrithms and how to organize them
  • visualization support

fix over-estimated seven pair win rate

For now, a hand with drawn tiles will be considered as win:

  1. IFF the union of the hand and drawings contains at least a win pattern.

But for seven pair win pattern, it will over-estimated much more than normal type wining. Infering from 1), the model will assume that all tiles which will form a pair will be choosen to keep in hand, but it is really hard (nearly impossible) to predict which tile will eventually form a pair (it seems all the same). The prediction from player is not statically significant different from random guessing.

For comparasion, 23s has nearly 2 times chances than 13s to form a meld, so choosing is quite easy.

(i.e. 1155m123345p5566s, 6 draws, it will consider to discard 1/5p to expect seven-pair wining, which is not acceptable by most of the players.)

fix 0s 0p representation and check 0s 0p in demo 'Monte Carlo estimation'

Now the demo 1(Monte Carlo estimation) do accept 0m, 0p, 0s as input, but not treated as aka 5m, aka 5p, aka 5s. Instead it is a tile with number zero, which is weird and buggy.
(mentioned in Pull Request #5 )

maybe first fix it by add restriction and conversion to normal 5s/5m/5p in demo, then discuss the representation for aka 5m.

add dict record parse for TenhouEvent

TenhouEvent now represent a event. due to issue #12 , we could add a method like to_uniform_paifu_record(self) to TenhouEvent ,return a plain dict() (dict-like) object to support easy pandas.Dataframe creation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.