mahjong.meld
- class mahjong.meld.Meld(meld_type=None, tiles=None, opened=True, called_tile=None, who=None, from_who=None)[source]
Representation of a declared meld (called or concealed tile group).
A meld is a set of tiles that a player has declared, either by calling another player’s discard (open meld) or by declaring a concealed kan. Meld types follow standard Japanese mahjong terminology:
Chi — a sequence of three consecutive suited tiles, called from the player to the left.
Pon — a triplet of identical tiles, called from any player.
Kan — a quad of identical tiles (open, closed, or extended).
Shouminkan — an added kan (extending an existing pon with the fourth tile).
Nuki — a special declaration used in three-player mahjong (north wind extraction).
Create an open chi meld:
>>> from mahjong.meld import Meld >>> from mahjong.tile import TilesConverter >>> tiles = TilesConverter.string_to_136_array(man="123") >>> meld = Meld(meld_type=Meld.CHI, tiles=tiles) >>> meld.type 'chi' >>> meld.tiles (0, 4, 8)
Create a closed kan:
>>> tiles = TilesConverter.string_to_136_array(man="1111") >>> meld = Meld(meld_type=Meld.KAN, tiles=tiles, opened=False) >>> meld.opened False
- Variables:
type (str | None) – one of the meld type constants (CHI, PON, KAN, SHOUMINKAN, NUKI)
tiles (tuple[int, ...]) – tile indices in 136-format, stored as an immutable tuple
opened (bool) – True for open melds (called from another player), False for closed kan
called_tile (int | None) – the specific tile index (136-format) that was called to form this meld
who (int | None) – seat index (0-3) of the player who declared the meld
from_who (int | None) – seat index (0-3) of the player who discarded the called tile
- Parameters:
meld_type (str | None)
tiles (tuple[int, ...])
opened (bool)
called_tile (int | None)
who (int | None)
from_who (int | None)
- CHI = 'chi'
Chi (sequence) meld type — three consecutive suited tiles.
- PON = 'pon'
Pon (triplet) meld type — three identical tiles.
- KAN = 'kan'
Kan (quad) meld type — four identical tiles.
- SHOUMINKAN = 'shouminkan'
Shouminkan (added kan) meld type — extending a pon with the fourth tile.
- NUKI = 'nuki'
Nuki (north wind extraction) meld type, at the moment is not used in the library.
- __init__(meld_type=None, tiles=None, opened=True, called_tile=None, who=None, from_who=None)[source]
Initialize a meld.
>>> from mahjong.meld import Meld >>> from mahjong.tile import TilesConverter >>> tiles = TilesConverter.string_to_136_array(man="111") >>> meld = Meld(meld_type=Meld.PON, tiles=tiles, who=0, from_who=2) >>> meld.type 'pon' >>> meld.who 0
- Parameters:
meld_type (str | None) – one of the meld type constants (CHI, PON, KAN, SHOUMINKAN, NUKI)
tiles (Sequence[int] | None) – tile indices in 136-format
opened (bool) – True for open melds (called from another player), False for closed kan
called_tile (int | None) – the specific tile index (136-format) that was called to form this meld
who (int | None) – seat index (0-3) of the player who declared the meld
from_who (int | None) – seat index (0-3) of the player who discarded the called tile
- Return type:
None
- property tiles_34: list[int]
Convert the meld’s 136-format tile indices to 34-format tile indices.
>>> from mahjong.meld import Meld >>> from mahjong.tile import TilesConverter >>> tiles = TilesConverter.string_to_136_array(man="111") >>> meld = Meld(meld_type=Meld.PON, tiles=tiles) >>> meld.tiles_34 [0, 0, 0]
- Returns:
list of tile indices in 34-format