本文へ移動

Kazu数

検証済みの数独や論理パズルを作り、標準の規則とヒントを読み、盤を描いたり埋め込んだりできます。

「数」は数字を表す言葉です。 名前について(英語)

目次

リファレンス · 数字パズルのエンジン

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:

  1. 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 (by says which, when one did);
  2. 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;
};

メンバー

名前型説明
cellnumber
valuenumber
why"only-number" | "only-place" | "answer"
group (省略可){ type: "row" | "column" | "box" | "region" | "diagonal"; index: number; } | undefined

only-place: the group the number has one place in.

by (省略可)"marks" | "cage" | "clues" | undefined

only-number: what ruled the others out beyond the groups, if anything did.

replacesboolean

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 }

出力(このページを作ったときに実行した結果)

ソースを見るGitHub で編集@johnmorrisdotca/kazu 2.1.0 のソースから作成しました。

この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。