Reference · Number-puzzle engines
KazuGametype
A PUZZLE IN PLAY, as pure functions: what has been written, the pencil marks, and how to take a
step back. Every function returns a new game and leaves the one it was given as it was, so a page
can keep them as its history, and a server can replay a solve with no page at all. mountKazu
is these functions with a drawing and a finger on them.
Import it
import type { KazuGame } from "@johnmorrisdotca/kazu";
Definition
type KazuGame = {
kind: KazuKind;
size: number;
givens: string;
printed: KazuGivens;
entries: readonly number[];
notes: readonly number[];
past: readonly {
entries: readonly number[];
notes: readonly number[];
}[];
};
Members
| Name | Type | Description |
|---|---|---|
kind | "number-place" | "jigsaw" | "diagonal" | "sum-cages" | "more-or-less" | "towers" | |
size | number | |
givens | string | The puzzle's givens code, as made. |
printed | KazuGivens | What the puzzle was printed with. |
entries | readonly number[] | What the player has written, row-major, 0 where nothing; always 0 on a printed cell. |
notes | readonly number[] | Pencil marks, a bit mask a cell: bit |
past | readonly { entries: readonly number[]; notes: readonly number[]; }[] | The grids before this one, newest last, for Undo. |
Examples
import type { KazuGame, KazuPuzzle } from "@johnmorrisdotca/kazu";
import { newKazuGame } from "@johnmorrisdotca/kazu";
const puzzle: KazuPuzzle = {"kind":"number-place","size":4,"level":"easy","seed":42,"givens":"14..2..1412.3..4","solution":"1432234141233214"};
const kind = puzzle.kind;
const size = puzzle.size;
const givens = puzzle.givens;
const game = newKazuGame(kind,size,givens)!;
const value: KazuGame = game;
console.log(value);{
kind: 'number-place',
size: 4,
givens: '14..2..1412.3..4',
printed: {
kind: 'number-place',
size: 4,
regions: [
0, 0, 1, 1, 0, 0,
1, 1, 2, 2, 3, 3,
2, 2, 3, 3
],
diagonals: false,
cages: null,
marks: [],
clues: null,
cells: [
1, 4, 0, 0, 2, 0,
0, 1, 4, 1, 2, 0,
3, 0, 0, 4
]
},
entries: [
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0
],
notes: [
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0
],
past: []
}What it prints (run when this page was built)