Reference · Tiles, layouts and deals
layPairsfunction
Lay these pairs of tiles into the slots present names, or null when no
attempt reached the end. Higher slots are a little likelier to be taken
first, which keeps the stacks coming down together and leaves fewer
attempts stuck on a tower of two.
Import it
import { layPairs } from "@johnmorrisdotca/jarajara";
Definition
function layPairs(geometry: MahjongGeometry, present: readonly boolean[], pairs: readonly (readonly [string, string])[], random: Random): Laid | null
Parameters
| Name | Type | Description |
|---|---|---|
geometry | MahjongGeometry | The stacked layout’s covering and side-blocking relationships. |
present | readonly boolean[] | Whether each native slot is still occupied or selected for laying. |
pairs | readonly (readonly [string, string])[] | Matching tile-face pairs to lay into slots. |
random | Random | A reproducible random source returning values in [0,1). |
Returns
Laid | null
Lay these pairs of tiles into the slots present names, or null when no attempt reached the end. Higher slots are a little likelier to be taken first, which keeps the stacks coming down together and leaves fewer attempts stuck on a tower of two.
Examples
import { generateAwase } from "@johnmorrisdotca/jarajara/awase";
import { geometryOf, layPairs, layoutFor, pairsLeft, seededRandom } from "@johnmorrisdotca/jarajara";
const deal = generateAwase(4,"easy",2026);
const layout = layoutFor(4)!;
const geometry = geometryOf(layout);
const cells = deal.givens;
console.log(layPairs(geometry,layout.slots.map(()=>true),pairsLeft(cells,"group"),seededRandom(42))?.order.length);4What it prints (run when this page was built)