Decks (TilePiles)
Tiles can also be collected into an abstract idea of a "pile of tiles." For example, this is intended to be used to represent the four walls of tiles in the game. Decks (called TilePile
s in code) have several properties:
- Ordered (but not sorted)
- Size strictly decreases
- Removal occurs strictly at the two ends of the pile
In this way, a TilePile
is like a deque that can only be removed from once it's been created.
MahjongTiles.TilePile
— TypeA pile of tiles. An abstraction for a collection of Mahjong tiles, similar to a deque.
Some properties:
- ordered and unsorted
- size only strictly decreases once created
MahjongTiles.TilePile
— MethodTilePile(tiles)
TilePile(name)
Create a particular predefined/standard TilePile
given the name
, or create the TilePile
from a specific list of tiles.
Supported Names
:standard
4 of each numbered tile from the 3 suits, plus 4 of each wind, 4 of each dragon, and the 8 flowers/seasons
TilePile
s support a limited set of operations that reflect allowable actions in the game, e.g. shuffling tiles, circshift
for determining where the ends of the pile are.
Removing from a TilePile
Base.pop!
— Methodpop!(tilepile)
Remove a tile from the end of the tile pile. Removing from this end is used for the usual pickup of tiles from the deck (not for flower/four-of-a-kind replacement).
Base.pop!
— Methodpop!(tilepile, num_tiles)
Remove num_tiles
tiles from the end of the tile pile as an array. Removing from this end is used for the usual pickup of tiles from the deck (not for flower/four-of-a-kind replacement).
Base.popfirst!
— Methodpopfirst!(tilepile)
Remove the "first" tile from the tile pile. Removing from this end is intended to be used for flower/four-of-a-kind replacement (this is to improve average performance).
Base.popfirst!
— Methodpopfirst!(tilepile, num_tiles)
Remove the "first" num_tiles
tiles from the tile pile as an array. Removing from this end is intended to be used for flower/four-of-a-kind replacement (this is to improve average performance).
Other Operations
These are other functions supported for the TilePile
type, which behave similar to the way they do in Julia Base.
length
first
last
circshift
circshift!
(this has a slightly different signature than in Base)shuffle!