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

Info

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.SuitType

The root abstract type for suit types. This is also used to represent "pseudo-suit" types, like the winds, dragons, flowers, etc.

source

which has the following interface:

FunctionDefaultDescription
is_sequential(suit_type)falseWhether this suit can be scored sequentially
max_number(suit_type)1The max number that this suit has
first_char(suit_type)-The Unicode character associated with the number 1 (required)
typical_duplication(suit_type)1The 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_sequentialFunction
is_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.

source
MahjongTiles.max_numberFunction
max_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.

source
MahjongTiles.first_charFunction
first_char(suit_type)

The character for the first tile in this suit (in Unicode).

Examples

julia> first_char(Character)
🀇
source

There are also 2 additional constants that list all of the implemented suits.

MahjongTiles.suitsConstant

List of the "normal" suits: character, bamboo, circles.

using MahjongTiles

MahjongTiles.suits
source

Tiles

MahjongTiles.TileType

The 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.

source

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.characterFunction
character(index)

Creates a tile of the character suit with the particular number.

Example

julia> character(5)
🀋
source
MahjongTiles.bambooFunction
bamboo(index)

Creates a tile of the bamboo suit with the particular number.

Example

julia> bamboo(2)
🀑
source
MahjongTiles.circleFunction
circle(index)

Creates a tile of the circle suit with the particular number.

Example

julia> circle(9)
🀡
source
MahjongTiles.windFunction
wind(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)
🀁
source
MahjongTiles.dragonFunction
dragon(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)
🀅
source
MahjongTiles.flowerFunction
flower(index)

Creates a flower tile with the particular number.

Note

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)
🀣
source
MahjongTiles.seasonFunction
season(index)

Creates a season (flower) tile with the particular number.

Note

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)
🀩
source