Skip to content

Commit ee8f587

Browse files
authored
docs: add yaku config documentation (#252)
* docs: add yaku config documentation * remove not needed code example * fix pyproject.toml
1 parent 8be09d9 commit ee8f587

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

mahjong/hand_calculating/yaku_config.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
"""
2+
Yaku configuration and ID mappings.
3+
4+
.. rubric:: Data
5+
6+
* :data:`YAKU_ID_TO_TENHOU_ID` - mapping from library yaku IDs to Tenhou yaku IDs
7+
8+
.. rubric:: Classes
9+
10+
* :class:`YakuConfig` - pre-instantiated collection of all yaku for condition checking
11+
12+
Look up a Tenhou yaku ID:
13+
14+
>>> from mahjong.hand_calculating.yaku_config import YAKU_ID_TO_TENHOU_ID
15+
>>> from mahjong.hand_calculating.yaku_list import Riichi
16+
>>> YAKU_ID_TO_TENHOU_ID[Riichi.yaku_id]
17+
1
18+
"""
19+
120
from mahjong.hand_calculating.yaku_list import (
221
AkaDora,
322
Chankan,
@@ -123,9 +142,39 @@
123142
UraDora.yaku_id: 53,
124143
AkaDora.yaku_id: 54,
125144
}
145+
"""
146+
Mapping from library :attr:`~mahjong.hand_calculating.yaku.Yaku.yaku_id` values
147+
to `Tenhou <https://tenhou.net/>`_ yaku IDs.
148+
149+
Useful for integrating with Tenhou log formats or displaying results
150+
in Tenhou-compatible order.
151+
"""
126152

127153

128154
class YakuConfig:
155+
"""
156+
Pre-instantiated collection of all yaku (winning patterns) for condition checking.
157+
158+
Each attribute is a :class:`~mahjong.hand_calculating.yaku.Yaku` instance that can
159+
check whether its condition is met for a given hand decomposition. Yaku are grouped
160+
by han value: situational yaku, 1-han, 2-han, 3-han, 6-han, yakuman,
161+
double yakuman, yakuman situations, and bonus dora.
162+
163+
A ``YakuConfig`` is automatically created as part of
164+
:class:`~mahjong.hand_calculating.hand_config.HandConfig`, so most users do not need
165+
to instantiate it directly. Direct instantiation is useful for checking individual
166+
yaku conditions outside the full hand evaluation pipeline.
167+
168+
Access yaku metadata:
169+
170+
>>> from mahjong.hand_calculating.yaku_config import YakuConfig
171+
>>> config = YakuConfig()
172+
>>> config.riichi.name
173+
'Riichi'
174+
>>> config.riichi.han_closed
175+
1
176+
"""
177+
129178
def __init__(self) -> None:
130179
# Yaku situations
131180
self.tsumo = Tsumo()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ convention = "pep257"
111111
"D", # pydocstyle
112112
"S101", # assert
113113
]
114+
"./mahjong/hand_calculating/yaku_config.py" = ["D107"] # __init__ only sets yaku instances
114115

115116
# temporary
116-
"./mahjong/hand_calculating/yaku_config.py" = ["D"]
117117
"./mahjong/hand_calculating/yaku.py" = ["D"]
118118
"./mahjong/hand_calculating/yaku_list/*" = ["D"]
119119

0 commit comments

Comments
 (0)