Skip to the content

Jarajaraジャラジャラ

Draw mahjong tiles, arrange racks and stacked boards, and play seeded Awase alone or at a shared table.

Jarajara is the Japanese sound of mahjong tiles rattling together. About the name

Contents

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

NameKindWhat it is
ALL_LAYOUTSconstantEvery 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.
arrangeIndexesfunctionThe 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.
arrangeTilesfunctionThe tiles in an order, as a new list; see arrangeIndexes for what each order is.
AwaseChecktypeWhat a check of a finished game says: cleared, or the first reason it is not.
AwaseDealtypeA deal of Awase: its layout's size, its level and seed, the tiles where they lie, and one way to clear them.
AwaseLeveltypeHow hard a deal of Awase is: the easiest of a seed's candidate deals to clear, the middle one, or the hardest.
blockedByfunctionWhy a tile cannot be taken now: covered by a tile on it, or held on both sides.
bonusRuleOffunctionThe 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.
canTakefunctionWhether these two slots are a pair that may be taken now.
copiesOffunctionHow many of a face the set holds: four of every ordinary face, one of each flower and season.
countTilesfunctionHow many of each face a list of tiles holds, by code; faces it holds none of are left out.
dealFitsfunctionWhether a deal is written right for a layout: one face a slot, nothing empty.
decodeMovesfunctionThe moves a string holds, each slot below slots; null for anything else.
describeSlotfunctionWhere 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_SLOTconstantThe cell marker for a tile already removed from the layout.
encodeMovesfunctionWrite pair takes and shuffles as the native compact move record.
faceOffunctionThe face a letter stands for, or null for anything that is not one.
faceWordsfunctionWhat a face is called, in English: "3 of characters", "east wind", "red dragon", "plum (flower)".
faceWordsJafunctionWhat a face is called in Japanese: 三萬, 五筒, 七索, 東, 中, 梅, 春.
findFacefunctionThe tile a text names, or null.
findFacesfunctionEvery tile a text names: the one face findFace finds, or, for the name of a group (winds, honours, circles), all of its faces.
freePairsfunctionEvery pair that could be taken now, each once, lower slot first, in slot order.
freeSlotsfunctionEvery free tile, by slot.
geometryOffunctionWhat lies on and beside each slot, worked out once for a layout and kept.
groupFacesfunctionThe faces of a group, in the set's order.
groupStartsfunctionThe 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.
groupTilesfunctionThe tiles split into the runs a gap is drawn between: by suit or by kind, each run in the set's order.
groupWordsfunctionWhat a group is called, in English and in Japanese.
hashTextfunctionA 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.
HinttypeA hint: the pair to show (the chosen tile first, for a match) and what kind of answer it is.
hintForfunctionA HINT, WHICH LOOKS FIRST FOR THE CHOSEN TILE'S MATCH.
HintKindtypeWhat 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).
isBonusfunctionA flower or a season: one of a kind in the set, and matched by its group under the usual rule.
isClearedfunctionWhether every tile has been taken.
isFaceCodefunctionWhether a single character names a supported tile face.
isFreefunctionWhether the tile in this slot is free.
isFreeAmongfunctionWhether a slot's tile could be taken now, among the slots present says are still filled.
isNotationfunctionWhether a text is written as hand notation, 123m456p: nothing but digit runs each closed by a suit letter.
isTileGroupfunctionWhether a text names a group.
kindOffunctionThe 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.
LaidtypeA deal laid out and the order it can be cleared in, pair by pair.
layoutExtentfunctionThe layout's extent in half units: how far right and down its tiles reach, and how many layers.
layoutForfunctionThe layout a size names, or null for one there is not.
layPairsfunctionLay these pairs of tiles into the slots present names, or null when no attempt reached the end.
MAHJONG_FACESconstantThe forty-two tile faces in stable code order, including bonus tiles.
MAHJONG_LAYOUTSconstantThe built-in native layouts in supported size order.
MahjongBonusRuletypeHow a flower or a season matches.
MahjongCellstypeThe tiles as they lie: a face code for each slot of the layout, "." where the tile has been taken.
MahjongFacetypeOne face of the set: its suit and its rank within it (1–9 for a suit, 1–4 or 1–3 for the rest).
MahjongGeometrytypeWhat 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.
MahjongLayouttypeA stacked layout: its slots in reading order (layer by layer, row by row), which is the order a deal is written in.
MahjongMovetypeOne move of a solve: a pair taken, by its two slots, or a shuffle of what is left.
MahjongSlottypeA place in a layout: a tile's top-left corner in half-tile units across and down, and its layer.
MahjongSuittypeThe suits and honours of a mahjong set, and the two kinds of bonus tile.
matchClassfunctionTHE MATCHING RULE.
matchesOffunctionEVERY TILE THAT MATCHES A SLOT'S, under the bonus rule in play, told apart by whether it could be taken with it now.
MatchesOftypeWhich 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_LAYOUTSconstantThe large native stacked layouts and their supported size identifiers.
mixTilesfunctionThe 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_LAYOUTSconstantThe additional native stacked layouts and their supported size identifiers.
overlapsOnLayerfunctionWhether two slots of one layer overlap, which no layout may have: a tile cannot share a place.
pairGoesAgainfunctionWhether taking this pair gives its taker another turn at the table: a flower or season pair.
pairPointsfunctionWHAT 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.
pairsLeftfunctionThe tiles left on a layout as pairs that match, each pair's tiles together: what a shuffle lays again.
playSolvefunctionPLAY 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.
RandomtypeA number in [0, 1), like Math.random, from a stream a seed fixes.
readNotationfunctionThe 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).
readSlotKeysfunctionThe keys a text names, "z y x", "x,-z", in order; anything that is no axis is dropped.
readTilesfunctionA 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.
ReplayedtypeWhere a solve stands after its moves: the tiles, and how many shuffles it has had.
seededRandomfunctionA stream of numbers in [0, 1) fixed by a seed.
setInventoryfunctionThe whole set as an inventory: each of the 42 faces and how many of it the 144 tiles hold.
setPairsfunctionEVERY 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_MARKconstantA 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 "*".
shuffledfunctionA copy of the list in a random order (Fisher–Yates); the list given is left alone.
shuffleTilesfunctionSHUFFLE: the tiles left, laid again in the slots they fill, so that play can go on.
SlotAxistypeWhat a layout's slots are put in order by: where a tile is across (x), down (y), and how high (z).
SlotSortKeytypeOne key of a sort: an axis, and - before it for the other way round (-z, the highest first).
sortSlotsfunctionThe 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_WORDSconstantWhat a suit or group is called, in English and in Japanese.
takePairfunctionThe tiles with a pair taken.
TILE_GROUPSconstantTHE 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_ORDERSconstantThe orders, in the order a list offers them.
TileGrouptypeA group's name.
TileGroupingtypeHow tiles are grouped, with a gap between groups: by suit (circles with circles), or by kind (numbers, honours, bonus tiles).
TileLanguagetypeThe two languages a tile is named in.
tileNamefunctionA tile's name in a language, from its code; the code itself for a letter that is no face.
TileOrdertypeHow a hand is put in order: as dealt, by suit then rank, by rank across the suits, by kind, or by the letters.
tilesLeftfunctionHow many tiles are still on the layout.
tilesMatchfunctionWhether two tile face codes match under the selected bonus rule.
VERSIONconstantThe package's version.
writeNotationfunctionTiles written the way hands are: digits then a suit letter, 123m456p789s1112z.
writeTilesfunctionTiles as their one-letter codes run together, abcF: what readTiles reads and a layout's cells are written in.

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/jarajara 1.7.0.