Hands

A Hand represents the set of tiles that a particular player has (varies in number, depending on the variety of Mahjong being played).

Supported Operations

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_pureFunction
is_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)]))
true
source
MahjongTiles.is_single_suitFunction
is_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)]))
true
source
MahjongTiles.has_dragon_tripleFunction
has_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
source