Reference
Rules, generation and deductions
import { … } from "@johnmorrisdotca/jirai";
7.8 kB minified and gzipped, with everything it imports (measured with esbuild)
Jirai 地雷: the rules and deductions, plain functions over plain data. No DOM and no dependencies.
Exports
| Name | Kind | What it is |
|---|---|---|
activeCell | function | Row-major addresses stay stable; omitted cells have no clue and no neighbours. |
activeCells | function | Returns all active cells in stable row-major order. |
Board | type | A dealt board including its answer; keep it off public clients. |
Constraint | type | An exact count over unknown cells, with the clues that supplied it. |
dailySeed | function | UTC by definition, so two people sharing a daily seed get the same board. |
decodeOrthogonalGame | function | Restores only version 2 orthogonal progress records. |
deduce | function | What the clues prove, without reading the answer or trusting a player's flags. |
Deduction | type | Certain safe cells and mines proved from visible clues. |
DEFAULT_SETTINGS | constant | Default easy game, with a verified no-guess board and clear opening. |
encodeOrthogonalGame | function | Encodes an orthogonal game with an explicit variant marker and version 2. |
ENUMERATION_CELLS | constant | Largest frontier enumerated for exact deductions. |
ENUMERATION_NODES | constant | Maximum partial assignments checked in one exact deduction search. |
Game | type | Rules data includes the answer; never send it to a competitive client. |
gameFromProgress | function | A saved game is rebuilt under the rules. |
gameProgress | function | Keep settings and moves, never an unchecked answer array. |
GENERATION_ATTEMPTS | constant | Default number of random layouts tried before a no-guess deal falls back to repairing the closest one. |
GenerationError | class | A bounded generator must say it failed, never quietly return a guessing board. |
GenerationOptions | type | Work limits for seeded board generation and its no-guess check. |
Grid | type | Neighbour topology used to count the clues around each cell. |
GRID_SPECS | constant | Neighbour offsets and edge behaviour for each topology. |
GRIDS | constant | Names for the supported square, four-neighbour, hex, and wrap grids. |
hintFor | function | Keep discovering certain mines until there is a safe cell or nothing more is proved. |
HUGE_SIZES | constant | The huge fields: four times the area of a 16×16 (the medium level), 1,024 to 1,152 squares, for a long solve. |
hugeSettings | function | The size and mine count of a level on a huge field: a field of HUGE_SIZES (32 × 32 unless size says another of them), with the level's own share of mines over its squares. |
HugeSize | type | The outline of a huge field: one of HUGE_SIZES' width and height. |
isSolvable | function | Verify a board from one opening, using only clues that have been uncovered. |
Language | type | Supported interface copy locales. |
Level | type | A difficulty level: easy, medium, hard or extra-hard. |
LEVEL_ALIASES | constant | The 0.1 and 0.2 names for the first three levels. |
LEVEL_SIZES | constant | Size and mine count of each level on a rectangular board. |
LevelAlias | type | The 0.1 and 0.2 names for easy, medium and hard, still accepted wherever a level is. |
levelNamed | function | The level a name means, or null. |
LEVELS | constant | The four difficulty levels, easiest first. |
levelSettings | function | The size and mine count of a level. |
LevelSize | type | Board size and mine count a level asks for. |
makeBoard | function | Deal after the first reveal. |
makeOrthogonalBoard | function | Deals a board whose clues count only up, down, left and right. |
Mark | type | Player-facing state of one cell; the answer is never a mark. |
MARKS | constant | Names for the cell mark cycle. |
Material | type | Board colours for drawing and mounted play. |
MAX_CELLS | constant | Largest total cell count accepted by settings validation. |
MAX_SIDE | constant | Largest width or height accepted by settings validation. |
Measure | type | How demanding a dealt board is to solve by deduction, measured by solving it. |
measureBoard | function | Solve a dealt board from its opening and report what it took. |
Move | type | A reveal, mark-cycle, or numbered-cell chord applied to a game. |
MOVES | constant | Names for the moves accepted by the engine. |
neighbours | function | Every neighbour once. |
neighboursOf | function | Precomputes the neighbour list for each row-major cell. |
newGame | function | Creates an unstarted game with covered cells and no dealt answer. |
newOrthogonalGame | function | Starts a game under four-neighbour rules. |
ORTHOGONAL_VARIANT | constant | Identifies the four-neighbour rules and progress-code format. |
orthogonalHint | function | Gives a clue-only deduction; flags remain notes and cannot influence the result. |
orthogonalNeighbours | function | Returns the adjacent cells under the orthogonal rules. |
OrthogonalSettings | type | Settings accepted by the four-neighbour-specific helpers. |
Pieces | type | Symbols used to mark mines. |
play | function | A legal move returns a new game; an unavailable move returns the same one. |
PRESETS | constant | Common minefield dimensions and mine counts. |
ProofKind | type | Why a cell was proved: one clue, two overlapping clues, the mine counter, or every arrangement of a small frontier. |
ProofTally | type | Cells proved by each kind of reasoning. |
seededRandom | function | Mulberry32, pinned by the replay tests: changing it would change every kept board. |
Settings | type | Board dimensions and rules used to deal and validate a game. |
SHAPES | constant | Board silhouettes supported by settings. |
Status | type | Current game state, including whether a mine has been hit. |
STATUSES | constant | Names for the game lifecycle states. |
validCell | function | Reports whether a row-major cell is inside the board's active shape. |
validSettings | function | Reject a setting before it reaches a board allocation or a shuffle. |
VERSION | constant | Package version, kept in step with the release metadata. |
visibleGame | function | The clue-only view used by the solver. |
VisibleGame | type | Answer-free state suitable for deductions, hints, and public display. |
withBoard | function | Attaches a worker-dealt board that matches the game's settings, preserving existing moves. |