Skip to content

zurukumo/kago-utils

Repository files navigation

kago-utils

Python用の麻雀ライブラリ。

Mahjong library for Python.

インストール

pip install kago-utils

使い方

牌姿の定義

from kago_utils.hai_group import HaiGroup

# from_codeの0は赤5を意味します。天鳳の牌理ツールと同じ仕様です。
tehai1 = HaiGroup.from_code("123m406p789s11122z")
tehai2 = HaiGroup.from_list34([0, 1, 2, 12, 13, 14, 24, 25, 26, 27, 27, 27, 28, 28])
tehai3 = HaiGroup.from_counter34([
    1, 1, 1, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 1, 1, 1, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 1, 1, 1,
    3, 2, 0, 0, 0, 0, 0
])

print(tehai1 == tehai2 == tehai3)  # True

from_list136from_counter136も同様に使えます。

向聴数の計算

from kago_utils.hai_group import HaiGroup
from kago_utils.shanten import calculate_shanten

# 手牌
tehai = HaiGroup.from_code("123m456p789s11122z")

# 向聴数
shanten = calculate_shanten(tehai)
print(shanten)  # -1

謝辞

  • tests/data/shanten/p_hon_10000.txt
  • tests/data/shanten/p_koku_10000.txt
  • tests/data/shanten/p_normal_10000.txt
  • tests/data/shanten/p_tin_10000.txt

は、あらの一人麻雀研究所 からお借りしました。

その他、一部のテストデータは天鳳の牌譜から作成しました。

Benchmark

https://zurukumo.github.io/kago-utils/dev/bench/

About

Mahjong library for Python

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors