KazuHint型
リファレンスの説明と例は英語です。見出しと目次は日本語です。
A HINT: the next cell a person could fill in by looking, and why.
It reasons from what is right on the grid so far (the printed numbers and every entry that agrees with the answer; a wrong entry is treated as empty, so a hint never builds on a mistake) the way a person does, one step at a time:
- a cell that only one number fits (
only-number): every other number is already in its row, column, box, region, diagonal or cage, or a cage's sum, a Futoshiki mark or a Skyscrapers clue rules it out (bysays which, when one did); - a number that fits only one cell of a group (
only-place): the row, column, box, region, diagonal or cage it must go in, and where.
When neither is left (a hard puzzle asks for a guess here) it says so (answer): the tightest
cell, whose number is the answer's, with no reason a single step gives. Null when every cell is
already right.
インポート
import type { KazuHint } from "@johnmorrisdotca/kazu";
定義
type KazuHint = {
cell: number;
value: number;
why: "only-number" | "only-place" | "answer";
group?: {
type: "row" | "column" | "box" | "region" | "diagonal";
index: number;
};
by?: "cage" | "marks" | "clues";
replaces: boolean;
};
メンバー
| 名前 | 型 | 説明 |
|---|---|---|
cell | number | |
value | number | |
why | "only-number" | "only-place" | "answer" | |
group (省略可) | { type: "row" | "column" | "box" | "region" | "diagonal"; index: number; } | undefined |
|
by (省略可) | "marks" | "cage" | "clues" | undefined |
|
replaces | boolean | Whether the cell holds a wrong number now, which this one replaces. |
例
import type { KazuHint, KazuPuzzle } from "@johnmorrisdotca/kazu";
import { decodeCells, readGivens } 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 answer = puzzle.solution;
const printed = readGivens(kind,size,givens)!;
const cells = printed.cells;
const solution = decodeCells(answer,size)!;
const blank = cells.findIndex(value=>value===0);
const value: KazuHint = {cell:blank,value:solution[blank],why:"answer",replaces:false};
console.log(value);{ cell: 2, value: 3, why: 'answer', replaces: false }出力(このページを作ったときに実行した結果)
この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。