Tile API
Tiles are sorted in "suits" or "pseudo-suits." Generally speaking, the usual "suited tiles" belong to the character, bamboo, or circle suits. The other tiles are not really in suits, but they can be treated programmatically as if they were. The normal suits are considered sequential suits; the other suits are considered non-sequential suits.
Suits
This is an internal implementation detail and is subject to change in future versions.
This is the current way that suits are implemented. All suit types inherit from a single abstract type
MahjongTiles.Suit
— TypeThe root abstract type for suit types. This is also used to represent "pseudo-suit" types, like the winds, dragons, flowers, etc.
which has the following interface:
Function | Default | Description |
---|---|---|
is_sequential(suit_type) | false | Whether this suit can be scored sequentially |
max_number(suit_type) | 1 | The max number that this suit has |
first_char(suit_type) | - | The Unicode character associated with the number 1 (required) |
typical_duplication(suit_type) | 1 | The typical number of tiles included in a deck with each tile in this suit |
Note that the first_char
method is required for printing, and if a new suit has max_number(suit_type) > 1
, it is assumed that they are consecutive in Unicode.
The way that these are currently implemented, each suit type is another abstract type
that inherits from Suit
. The required methods operate on the type and not instances of the type.
MahjongTiles.is_sequential
— Functionis_sequential(suit_type)
Check whether this suit type (or pseudo-suit) is a sequential one (for the purposes of hands). For example, typically the characters suit is sequential, but the winds suit is not.
MahjongTiles.max_number
— Functionmax_number(suit_type)
The maximum ("index") number for this suit type (or pseudo-suit). For example, the traditional suited tiles (characters, bamboo, circle) have a max of 9 (starting at 1), whereas the winds pseudo-suit has a max of 4.
MahjongTiles.first_char
— Functionfirst_char(suit_type)
The character for the first tile in this suit (in Unicode).
Examples
julia> first_char(Character)
🀇
MahjongTiles.typical_duplication
— Functiontypical_duplication(suit_type)
The number of duplicate tiles usually used for this suit type (this is usually 1 or 4).
There are also 2 additional constants that list all of the implemented suits.
MahjongTiles.suits
— ConstantList of the "normal" suits: character, bamboo, circles.
using MahjongTiles
MahjongTiles.suits
MahjongTiles.all_suits
— ConstantList of all suits, including "pseudo-suits" like the winds and flowers.
Tiles
MahjongTiles.Tile
— TypeThe root tile type for Mahjong tiles. However, the contract for what the Tile interface entails is not well-defined, so most functions dispatch on the SuitedTile
and not on Tile
.
MahjongTiles.SuitedTile
— TypeA tile with a suit (or pseudo-suit).
Accessing Specific Tiles
All of the standard tiles are exported as constants from the MahjongTiles module, so they can be directly accessed (e.g. for comparisons).
julia> 🀘
🀘
julia> 🀛 < 🀞
true
However, this means that it is difficult to type these without already knowing how to type them. To mitigate this, there are helper functions to create tiles of each suit.
MahjongTiles.character
— Functioncharacter(index)
Creates a tile of the character suit with the particular number.
Example
julia> character(5)
🀋
MahjongTiles.bamboo
— Functionbamboo(index)
Creates a tile of the bamboo suit with the particular number.
Example
julia> bamboo(2)
🀑
MahjongTiles.circle
— Functioncircle(index)
Creates a tile of the circle suit with the particular number.
Example
julia> circle(9)
🀡
MahjongTiles.wind
— Functionwind(index)
wind(direction)
Creates a wind tile. If an integer is used, the standard Chinese ordering of the cardinal directions is used (i.e. 1
-> east, 2
-> south, 3
-> west, 4
-> north). Otherwise, symbols can also be used for the names of the directions (e.g. :east
, :north
).
Example
julia> wind(:north)
🀃
julia> wind(2)
🀁
MahjongTiles.dragon
— Functiondragon(index)
dragon(name)
Creates a wind tile. If an integer is used, the standard ordering is used (i.e. 1
-> red dragon, 2
-> green dragon, 3
-> white dragon). Otherwise, symbols can also be used for their names/colors (e.g. :red
, :green
).
Example
julia> dragon(:red)
🀄
julia> dragon(2)
🀅
MahjongTiles.flower
— Functionflower(index)
Creates a flower tile with the particular number.
While this function (and the season
function) don't allow using the flower (season) names, they may have this functionality in the future.
Example
julia> flower(2)
🀣
MahjongTiles.season
— Functionseason(index)
Creates a season (flower) tile with the particular number.
While this function (and the flower
function) don't allow using the season (flower) names, they may have this functionality in the future.
Example
julia> season(4)
🀩