Reference
Tiles, layouts and deals
import { … } from "@johnmorrisdotca/jarajara";
7.9 kB minified and gzipped, with everything it imports (measured with esbuild)
Jarajara: mahjong tiles for JavaScript and TypeScript. The full set of 144 tiles in 42 faces, the stacked layouts
tile games are played on, which tiles are free, matching, dealing, shuffling and a game written as text. The
games are their own entries: @johnmorrisdotca/jarajara/awase (the matching solitaire) and
@johnmorrisdotca/jarajara/table (Awase for two to four, pairs that score).
Exports
| Name | Kind | What it is |
|---|---|---|
ALL_LAYOUTS | constant | Every layout there is: the five above, which itsutsu.com's kept games are made on and which never change, then Jarajara's own more (layouts-more.ts), each of a width none of the others has. |
arrangeIndexes | function | The places the tiles take in an order, as the numbers of the tiles in the order they come: [2, 0, 1] has the third tile first. |
arrangeTiles | function | The tiles in an order, as a new list; see arrangeIndexes for what each order is. |
AwaseCheck | type | What a check of a finished game says: cleared, or the first reason it is not. |
AwaseDeal | type | A deal of Awase: its layout's size, its level and seed, the tiles where they lie, and one way to clear them. |
AwaseLevel | type | How hard a deal of Awase is: the easiest of a seed's candidate deals to clear, the middle one, or the hardest. |
blockedBy | function | Why a tile cannot be taken now: covered by a tile on it, or held on both sides. |
bonusRuleOf | function | The deal's rule, read from the deal itself: a bonus tile dealt twice can only be the Identical rule, since the usual one deals each flower and season once. |
canTake | function | Whether these two slots are a pair that may be taken now. |
copiesOf | function | How many of a face the set holds: four of every ordinary face, one of each flower and season. |
countTiles | function | How many of each face a list of tiles holds, by code; faces it holds none of are left out. |
dealFits | function | Whether a deal is written right for a layout: one face a slot, nothing empty. |
decodeMoves | function | The moves a string holds, each slot below slots; null for anything else. |
describeSlot | function | Where a slot is, in tiles: across and down from the layout's corner (halves where a tile sits between two), and which layer, from 1. |
EMPTY_SLOT | constant | The cell marker for a tile already removed from the layout. |
encodeMoves | function | Write pair takes and shuffles as the native compact move record. |
faceOf | function | The face a letter stands for, or null for anything that is not one. |
faceWords | function | What a face is called, in English: "3 of characters", "east wind", "red dragon", "plum (flower)". |
faceWordsJa | function | What a face is called in Japanese: 三萬, 五筒, 七索, 東, 中, 梅, 春. |
findFace | function | The tile a text names, or null. |
findFaces | function | Every tile a text names: the one face findFace finds, or, for the name of a group (winds, honours, circles), all of its faces. |
freePairs | function | Every pair that could be taken now, each once, lower slot first, in slot order. |
freeSlots | function | Every free tile, by slot. |
geometryOf | function | What lies on and beside each slot, worked out once for a layout and kept. |
groupFaces | function | The faces of a group, in the set's order. |
groupStarts | function | The places in a list, already in order, where a new group starts: every place whose tile is of another suit (or kind) than the one before it. |
groupTiles | function | The tiles split into the runs a gap is drawn between: by suit or by kind, each run in the set's order. |
groupWords | function | What a group is called, in English and in Japanese. |
hashText | function | A 32-bit FNV-1a hash of a string: the seed a shuffle is drawn from, so the same tiles shuffled the same time come out the same. |
Hint | type | A hint: the pair to show (the chosen tile first, for a match) and what kind of answer it is. |
hintFor | function | A HINT, WHICH LOOKS FIRST FOR THE CHOSEN TILE'S MATCH. |
HintKind | type | What a hint found: a pair with the chosen tile in it (match), another pair because the chosen tile has no free match (other), a pair when no tile was chosen (any), or no pair at all (none). |
isBonus | function | A flower or a season: one of a kind in the set, and matched by its group under the usual rule. |
isCleared | function | Whether every tile has been taken. |
isFaceCode | function | Whether a single character names a supported tile face. |
isFree | function | Whether the tile in this slot is free. |
isFreeAmong | function | Whether a slot's tile could be taken now, among the slots present says are still filled. |
isNotation | function | Whether a text is written as hand notation, 123m456p: nothing but digit runs each closed by a suit letter. |
isTileGroup | function | Whether a text names a group. |
kindOf | function | The kind of a tile: 0 numbers (characters, circles, bamboo), 1 honours (winds, dragons), 2 bonus tiles (flowers, seasons); 3 for a letter that is none. |
Laid | type | A deal laid out and the order it can be cleared in, pair by pair. |
layoutExtent | function | The layout's extent in half units: how far right and down its tiles reach, and how many layers. |
layoutFor | function | The layout a size names, or null for one there is not. |
layPairs | function | Lay these pairs of tiles into the slots present names, or null when no attempt reached the end. |
MAHJONG_FACES | constant | The forty-two tile faces in stable code order, including bonus tiles. |
MAHJONG_LAYOUTS | constant | The built-in native layouts in supported size order. |
MahjongBonusRule | type | How a flower or a season matches. |
MahjongCells | type | The tiles as they lie: a face code for each slot of the layout, "." where the tile has been taken. |
MahjongFace | type | One face of the set: its suit and its rank within it (1–9 for a suit, 1–4 or 1–3 for the rest). |
MahjongGeometry | type | What stands on and beside each slot, worked out once per layout: the slots over it (any higher layer overlapping it), and the slots touching its left and right sides on its own layer. |
MahjongLayout | type | A stacked layout: its slots in reading order (layer by layer, row by row), which is the order a deal is written in. |
MahjongMove | type | One move of a solve: a pair taken, by its two slots, or a shuffle of what is left. |
MahjongSlot | type | A place in a layout: a tile's top-left corner in half-tile units across and down, and its layer. |
MahjongSuit | type | The suits and honours of a mahjong set, and the two kinds of bonus tile. |
matchClass | function | THE MATCHING RULE. |
matchesOf | function | EVERY TILE THAT MATCHES A SLOT'S, under the bonus rule in play, told apart by whether it could be taken with it now. |
MatchesOf | type | Which tile Find would show for a slot: the ones that could be taken with it now, and the ones that match but are held. |
MEGA_LAYOUTS | constant | The large native stacked layouts and their supported size identifiers. |
mixTiles | function | The same tiles in another order, at random, or the same order for the same seed; never the order they were in unless there is only one to be in. |
MORE_LAYOUTS | constant | The additional native stacked layouts and their supported size identifiers. |
overlapsOnLayer | function | Whether two slots of one layer overlap, which no layout may have: a tile cannot share a place. |
pairGoesAgain | function | Whether taking this pair gives its taker another turn at the table: a flower or season pair. |
pairPoints | function | WHAT A PAIR IS WORTH AT THE TABLE (table.ts): the plain suit tiles one, the ones and nines two, the winds three and the dragons four — the honours and terminals are the tiles a mahjong hand prizes — and a flower or season pair two, with another turn, as a bonus tile draws again in the full game. |
pairsLeft | function | The tiles left on a layout as pairs that match, each pair's tiles together: what a shuffle lays again. |
playSolve | function | PLAY THE MOVES ON THE DEAL, refusing the first that the rules do not allow: a pair that is not two free tiles that match, or a shuffle while a pair could still be taken (Shuffle is for when you are stuck), or one that cannot help. |
Random | type | A number in [0, 1), like Math.random, from a stream a seed fixes. |
readNotation | function | The tiles a hand's notation writes, as codes in the order written; null when the text is not notation or names a tile there is not (8z). |
readSlotKeys | function | The keys a text names, "z y x", "x,-z", in order; anything that is no axis is dropped. |
readTiles | function | A LIST OF TILES AS TEXT, read the forgiving way: each word is a tile's name (east, red-dragon, 3p) or a run of one-letter codes (abcF), and hand notation (123m456p) is read as it is written. |
Replayed | type | Where a solve stands after its moves: the tiles, and how many shuffles it has had. |
seededRandom | function | A stream of numbers in [0, 1) fixed by a seed. |
setInventory | function | The whole set as an inventory: each of the 42 faces and how many of it the 144 tiles hold. |
setPairs | function | EVERY PAIR THE SET HOLDS, 72 of them: each ordinary face twice (four copies), and the eight bonus tiles as four pairs — two flowers and two seasons, split at random under the usual rule, or four faces drawn twice each under the Identical rule. |
SHUFFLE_MARK | constant | A SOLVE AS IT IS WRITTEN: every move in order, a pair as its two slots in two base-36 characters each ("0a1c"), a shuffle as "*". |
shuffled | function | A copy of the list in a random order (Fisher–Yates); the list given is left alone. |
shuffleTiles | function | SHUFFLE: the tiles left, laid again in the slots they fill, so that play can go on. |
SlotAxis | type | What a layout's slots are put in order by: where a tile is across (x), down (y), and how high (z). |
SlotSortKey | type | One key of a sort: an axis, and - before it for the other way round (-z, the highest first). |
sortSlots | function | The slots of a layout, as their numbers, put in order by the keys: ["z", "y", "x"] is layer by layer, row by row, across (the layout's own order), ["x"] lines them up from the left, ["-z"] has the top of the stacks first. |
SUIT_WORDS | constant | What a suit or group is called, in English and in Japanese. |
takePair | function | The tiles with a pair taken. |
TILE_GROUPS | constant | THE GROUPS A SET FALLS INTO, for a viewer: each suit, and the bigger families people name them by: honours (winds and dragons), bonus (flowers and seasons), the numbers (the three suits), and the terminals (the ones and nines) and simples (two to eight) a hand is judged by. |
TILE_ORDERS | constant | The orders, in the order a list offers them. |
TileGroup | type | A group's name. |
TileGrouping | type | How tiles are grouped, with a gap between groups: by suit (circles with circles), or by kind (numbers, honours, bonus tiles). |
TileLanguage | type | The two languages a tile is named in. |
tileName | function | A tile's name in a language, from its code; the code itself for a letter that is no face. |
TileOrder | type | How a hand is put in order: as dealt, by suit then rank, by rank across the suits, by kind, or by the letters. |
tilesLeft | function | How many tiles are still on the layout. |
tilesMatch | function | Whether two tile face codes match under the selected bonus rule. |
VERSION | constant | The package's version. |
writeNotation | function | Tiles written the way hands are: digits then a suit letter, 123m456p789s1112z. |
writeTiles | function | Tiles as their one-letter codes run together, abcF: what readTiles reads and a layout's cells are written in. |