xiangting
A library for calculating the deficiency number (a.k.a. xiàngtīng number, 向聴数).
Documentation:
References
- [麻雀]シャンテン数計算アルゴリズム #C++ - Qiita
- 5. 集合漸化式 - 麻雀アルゴリズム
- 【図解】向聴数計算アルゴリズム - 麻雀アルゴリズム
- Theoretical Background of Nyanten (Efficient Computation of Shanten/Deficiency Numbers) #麻雀 - Qiita
- A Fast and Space-Efficient Algorithm for Calculating Deficient Numbers (a.k.a. Shanten Numbers).pdf
Language Bindings
- Python: xiangting-py
Installation
Usage
Basic Usage
The hand is represented as an array of [u8; 34], where each element represents the count of a specific tile.
The correspondence between the index and the tile is shown in the table below.
| Index | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|---|
| Tile | 1m | 2m | 3m | 4m | 5m | 6m | 7m | 8m | 9m |
| Index | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
|---|---|---|---|---|---|---|---|---|---|
| Tile | 1p | 2p | 3p | 4p | 5p | 6p | 7p | 8p | 9p |
| Index | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
|---|---|---|---|---|---|---|---|---|---|
| Tile | 1s | 2s | 3s | 4s | 5s | 6s | 7s | 8s | 9s |
| Index | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
|---|---|---|---|---|---|---|---|
| Tile | East (1z) | South (2z) | West (3z) | North (4z) | White (5z) | Green (6z) | Red (7z) |
Calculates the replacement number, which is equal to the deficiency number (a.k.a. xiàngtīng number, 向聴数) + 1.
use ;
Necessary and Unnecessary Tiles
It is also possible to calculate necessary or unnecessary tiles together with the replacement number.
-
Necessary tiles
- Tiles needed to win with the minimum number of replacements
- Tiles that reduce the replacement number when drawn
- In Japanese, these are referred to as 有効牌 (yūkōhai) or 受け入れ (ukeire)
-
Unnecessary tiles
- Tiles not needed to win with the minimum number of replacements
- Tiles that can be discarded without changing the replacement number
- In Japanese, these are referred to as 不要牌 (fuyōhai) or 余剰牌 (yojōhai)
use ;
Support for Three-Player Mahjong
In three-player mahjong, the tiles from 2m (二萬) to 8m (八萬) are not used.
use ;
Build tables and maps (For developers only)
&&
License
Copyright (c) Apricot S. All rights reserved.
Licensed under the MIT license.