Skip to the content

Kazu数

Generate checked Sudoku and logic puzzles, read native rules and hints, and draw or embed playable boards.

Kazu is the Japanese word 数 for number. About the name

Contents

Reference · Number-puzzle engines

cageOutlinefunction

THE DASHED OUTLINE OF EVERY CAGE, as line segments in cell units: each cage drawn a little inside its own edge, the way a printed Killer Sudoku draws it, so a cage reads as a shape within the box rules rather than as one of them.

Each cell draws the sides where its neighbour is in another cage, inset inside the cell. Where the cage goes on past a side's end, the line runs on to meet the next line of the outline: to the cell's edge when the cage's edge carries on straight, and inset past it at an inside corner, where the outline turns back into the cage. That is what makes the lines of one cage meet, with no gap and no overshoot, whatever its shape.

Import it

import { cageOutline } from "@johnmorrisdotca/kazu";

Definition

function cageOutline(size: number, cageOf: (index: number) => number | undefined, inset?: number): Segment[]

Parameters

NameTypeDescription
sizenumber

The supported square grid side length.

cageOf(index: number) => number | undefined

Map a cell index to its containing cage number, or undefined for none.

inset (optional)number

The outline inset in drawing units.

Returns

Segment[]

THE DASHED OUTLINE OF EVERY CAGE, as line segments in cell units: each cage drawn a little inside its own edge, the way a printed Killer Sudoku draws it, so a cage reads as a shape within the box rules rather than as one of them.

Examples

import type { KazuPuzzle } from "@johnmorrisdotca/kazu";
import { cageOutline, decodeKiller, 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 printed = readGivens(kind,size,givens)!;
const cells = printed.cells;
const killer = decodeKiller("2.....3..2................2...4.....012333412567882967aaa9bbccd9ebfgggee02050c0d03020309080e0c0a06020b040a",6)!;
console.log(cageOutline(6,index=>killer.cages.findIndex(cage=>cage.cells.includes(index))));
[
  { x1: 0.12, y1: 0.12, x2: 0.88, y2: 0.12 },
  { x1: 0.12, y1: 0.88, x2: 0.88, y2: 0.88 },
  { x1: 0.12, y1: 0.12, x2: 0.12, y2: 0.88 },
  { x1: 0.88, y1: 0.12, x2: 0.88, y2: 0.88 },
  { x1: 1.12, y1: 0.12, x2: 1.88, y2: 0.12 },
  { x1: 1.12, y1: 0.12, x2: 1.12, y2: 1 },
  { x1: 1.88, y1: 0.12, x2: 1.88, y2: 1 },
  { x1: 2.12, y1: 0.12, x2: 2.88, y2: 0.12 },
  { x1: 2.12, y1: 0.12, x2: 2.12, y2: 1 },
  { x1: 2.88, y1: 0.12, x2: 2.88, y2: 1 },
  { x1: 3.12, y1: 0.12, x2: 4, y2: 0.12 },
  { x1: 3.12, y1: 0.88, x2: 4, y2: 0.88 },
  { x1: 3.12, y1: 0.12, x2: 3.12, y2: 0.88 },
  { x1: 4, y1: 0.12, x2: 5, y2: 0.12 },
  { x1: 4, y1: 0.88, x2: 5, y2: 0.88 },
  { x1: 5, y1: 0.12, x2: 5.88, y2: 0.12 },
  { x1: 5, y1: 0.88, x2: 5.88, y2: 0.88 },
  { x1: 5.88, y1: 0.12, x2: 5.88, y2: 0.88 },
  { x1: 0.12, y1: 1.12, x2: 0.88, y2: 1.12 },
  { x1: 0.12, y1: 1.88, x2: 0.88, y2: 1.88 },
  { x1: 0.12, y1: 1.12, x2: 0.12, y2: 1.88 },
  { x1: 0.88, y1: 1.12, x2: 0.88, y2: 1.88 },
  { x1: 1.12, y1: 1.88, x2: 1.88, y2: 1.88 },
  { x1: 1.12, y1: 1, x2: 1.12, y2: 1.88 },
  { x1: 1.88, y1: 1, x2: 1.88, y2: 1.88 },
  { x1: 2.12, y1: 1, x2: 2.12, y2: 2 },
  { x1: 2.88, y1: 1, x2: 2.88, y2: 2 },
  { x1: 3.12, y1: 1.12, x2: 3.88, y2: 1.12 },
  { x1: 3.12, y1: 1.88, x2: 3.88, y2: 1.88 },
  { x1: 3.12, y1: 1.12, x2: 3.12, y2: 1.88 },
  { x1: 3.88, y1: 1.12, x2: 3.88, y2: 1.88 },
  { x1: 4.12, y1: 1.12, x2: 4.88, y2: 1.12 },
  { x1: 4.12, y1: 1.12, x2: 4.12, y2: 2 },
  { x1: 4.88, y1: 1.12, x2: 4.88, y2: 2 },
  { x1: 5.12, y1: 1.12, x2: 5.88, y2: 1.12 },
  { x1: 5.12, y1: 1.12, x2: 5.12, y2: 2 },
  { x1: 5.88, y1: 1.12, x2: 5.88, y2: 2 },
  { x1: 0.12, y1: 2.12, x2: 1, y2: 2.12 },
  { x1: 0.12, y1: 2.88, x2: 1, y2: 2.88 },
  { x1: 0.12, y1: 2.12, x2: 0.12, y2: 2.88 },
  { x1: 1, y1: 2.12, x2: 1.88, y2: 2.12 },
  { x1: 1, y1: 2.88, x2: 1.88, y2: 2.88 },
  { x1: 1.88, y1: 2.12, x2: 1.88, y2: 2.88 },
  { x1: 2.12, y1: 2.88, x2: 2.88, y2: 2.88 },
  { x1: 2.12, y1: 2, x2: 2.12, y2: 2.88 },
  { x1: 2.88, y1: 2, x2: 2.88, y2: 2.88 },
  { x1: 3.12, y1: 2.12, x2: 3.88, y2: 2.12 },
  { x1: 3.12, y1: 2.12, x2: 3.12, y2: 3 },
  { x1: 3.88, y1: 2.12, x2: 3.88, y2: 3 },
  { x1: 4.12, y1: 2.88, x2: 4.88, y2: 2.88 },
  { x1: 4.12, y1: 2, x2: 4.12, y2: 2.88 },
  { x1: 4.88, y1: 2, x2: 4.88, y2: 2.88 },
  { x1: 5.12, y1: 2.88, x2: 5.88, y2: 2.88 },
  { x1: 5.12, y1: 2, x2: 5.12, y2: 2.88 },
  { x1: 5.88, y1: 2, x2: 5.88, y2: 2.88 },
  { x1: 0.12, y1: 3.12, x2: 1, y2: 3.12 },
  { x1: 0.12, y1: 3.88, x2: 1, y2: 3.88 },
  { x1: 0.12, y1: 3.12, x2: 0.12, y2: 3.88 },
  { x1: 1, y1: 3.12, x2: 2, y2: 3.12 },
  { x1: 1, y1: 3.88, x2: 2, y2: 3.88 },
  { x1: 2, y1: 3.12, x2: 2.88, y2: 3.12 },
  { x1: 2, y1: 3.88, x2: 2.88, y2: 3.88 },
  { x1: 2.88, y1: 3.12, x2: 2.88, y2: 3.88 },
  { x1: 3.12, y1: 3, x2: 3.12, y2: 4 },
  { x1: 3.88, y1: 3, x2: 3.88, y2: 4 },
  { x1: 4.12, y1: 3.12, x2: 5, y2: 3.12 },
  { x1: 4.12, y1: 3.88, x2: 5.12, y2: 3.88 },
  { x1: 4.12, y1: 3.12, x2: 4.12, y2: 3.88 },
  { x1: 5, y1: 3.12, x2: 5.88, y2: 3.12 },
  { x1: 5.88, y1: 3.12, x2: 5.88, y2: 4 },
  { x1: 0.12, y1: 4.12, x2: 1, y2: 4.12 },
  { x1: 0.12, y1: 4.88, x2: 1, y2: 4.88 },
  { x1: 0.12, y1: 4.12, x2: 0.12, y2: 4.88 },
  { x1: 1, y1: 4.12, x2: 1.88, y2: 4.12 },
  { x1: 1, y1: 4.88, x2: 1.88, y2: 4.88 },
  { x1: 1.88, y1: 4.12, x2: 1.88, y2: 4.88 },
  { x1: 2.12, y1: 4.12, x2: 2.88, y2: 4.12 },
  { x1: 2.12, y1: 4.88, x2: 2.88, y2: 4.88 },
  { x1: 2.12, y1: 4.12, x2: 2.12, y2: 4.88 },
  { x1: 2.88, y1: 4.12, x2: 2.88, y2: 4.88 },
  { x1: 3.12, y1: 4.88, x2: 3.88, y2: 4.88 },
  { x1: 3.12, y1: 4, x2: 3.12, y2: 4.88 },
  { x1: 3.88, y1: 4, x2: 3.88, y2: 4.88 },
  { x1: 4.12, y1: 4.12, x2: 4.88, y2: 4.12 },
  { x1: 4.12, y1: 4.12, x2: 4.12, y2: 5 },
  { x1: 4.88, y1: 4.12, x2: 4.88, y2: 5.12 },
  { x1: 5.12, y1: 4.88, x2: 5.88, y2: 4.88 },
  { x1: 5.12, y1: 3.88, x2: 5.12, y2: 4.88 },
  { x1: 5.88, y1: 4, x2: 5.88, y2: 4.88 },
  { x1: 0.12, y1: 5.12, x2: 0.88, y2: 5.12 },
  { x1: 0.12, y1: 5.88, x2: 0.88, y2: 5.88 },
  { x1: 0.12, y1: 5.12, x2: 0.12, y2: 5.88 },
  { x1: 0.88, y1: 5.12, x2: 0.88, y2: 5.88 },
  { x1: 1.12, y1: 5.12, x2: 2, y2: 5.12 },
  { x1: 1.12, y1: 5.88, x2: 2, y2: 5.88 },
  { x1: 1.12, y1: 5.12, x2: 1.12, y2: 5.88 },
  { x1: 2, y1: 5.12, x2: 3, y2: 5.12 },
  { x1: 2, y1: 5.88, x2: 3, y2: 5.88 },
  { x1: 3, y1: 5.12, x2: 3.88, y2: 5.12 },
  { x1: 3, y1: 5.88, x2: 3.88, y2: 5.88 },
  ... 6 more items
]

What it prints (run when this page was built)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/kazu 2.1.0.