Hands
A Hand represents the set of tiles that a particular player has (varies in number, depending on the variety of Mahjong being played).
MahjongTiles.Hand — TypeRepresents the tiles in a single player's hand.
Supported Operations
push_hidden!(hand, tiles...)
Base.push!(hand, tiles...)Add a tile or tiles to the hidden part of the hand.
MahjongTiles.push_exposed! — Functionpush_exposed!(hand, tiles...)Add a tile or tiles to the open/exposed part of the hand.
MahjongTiles.expose! — Functionexpose!(hand, tiles...)Expose/make open the tiles from the hand.
Hands also support the following operations that behave similarly to how they do in Julia Base:
- iteration
first
Scoring Functions
Hands can be checked for whether they have certain configurations/arrangements of tiles (e.g. contain no winds, contain only tiles that are completely green, contain all threes-of-a-kind). There are roughly 2 kinds:
- those that describe a property of the entire hand (e.g. all sets must include the number 5), and
- those that describe a smaller arrangement of tiles that must be present somewhere in the hand (e.g. two threes-in-a-row of different suits, the other tiles are not considered).
The former are generally prefixed with is_ and the latter with has_.
In a way, these are not "scoring" functions, as they don't assign a score for each configuration, but only whether the configuration applies.
MahjongTiles.is_pure — Functionis_pure(hand)Determine whether the hand is pure (清). A hand is considered pure if there are no winds or dragons.
Example
julia> using MahjongTiles: wind, character, dragon, bamboo, circle, Hand, is_pure
julia> is_pure(Hand([wind(:east), character(3)]))
false
julia> is_pure(Hand([character(3), dragon(:green)]))
false
julia> is_pure(Hand([bamboo(8), character(3), circle(1)]))
trueMahjongTiles.is_single_suit — Functionis_single_suit(hand)Determine whether the hand consists of a single suit (一色), which can include non-suits like winds or flowers. To determine if the hand is only exactly a single suit, excluding winds, dragons, and flowers/seasons, combine this function with is_pure.
Example
julia> using MahjongTiles: wind, flower, character, circle, bamboo, Hand, is_single_suit
julia> is_single_suit(Hand([character(1), character(4), character(8), flower(3)]))
true
julia> is_single_suit(Hand([character(5), circle(5), bamboo(5)]))
false
julia> is_single_suit(Hand([circle(1), circle(7), wind(:north), wind(:east)]))
trueMahjongTiles.has_dragon_triple — Functionhas_dragon_triple(hand)Determine whether the hand has a triple of any one of the three dragon tiles.
Example
julia> using MahjongTiles: dragon, wind, bamboo, Hand, has_dragon_triple
julia> has_dragon_triple(Hand([dragon(:red), dragon(:red), dragon(:red), bamboo(2), wind(:east)]))
true
julia> has_dragon_triple(Hand([dragon(:red), dragon(:red), dragon(:green), dragon(:white)]))
false