Skip to the content

Tsunagi繋ぎ

Join each pair with a separate line and fill the board, through fixed levels or seeded puzzles.

Tsunagi means joining in Japanese. About the name

Contents

Reference · Rules, solvers and generation

withPortalsfunction

A filling with portals put in: each portal is made by joining two lines into one that goes into a ring and out of another, and the two cells it takes are the portal. Where line A runs … a, P1, … and line B runs … P2, b … with b on from P2 the way P1 is on from a, a new line runs A up to P1, the portal, and B on from b; what is left of A after P1 and of B before P2 are lines of their own, or nothing. Null where count portals cannot be made.

Import it

import { withPortals } from "@johnmorrisdotca/tsunagi";

Definition

function withPortals(size: number, paths: readonly number[][], random: Random, count: number, wrap: boolean): { paths: number[][]; pairs: [number, number][]; } | null

Parameters

NameTypeDescription
sizenumber

The number of cells on each side of the board.

pathsreadonly number[][]

The complete grid-filling cell paths.

randomRandom

A reproducible random source returning values in [0,1).

countnumber

The number of portals or levels specified by this signature.

wrapboolean

Whether opposite board edges connect.

Returns

{ paths: number[][]; pairs: [number, number][]; } | null

The transformed paths and portal pairs, or null when no compatible portal placement exists.

Examples

import { TSUNAGI_4 } from "@johnmorrisdotca/tsunagi/levels-4";
import { decodeLayout, linesOfAnswer, seededRandom, withPortals } from "@johnmorrisdotca/tsunagi";

const givens = TSUNAGI_4[0][0];
const answer = TSUNAGI_4[0][1];
const layout = decodeLayout(givens,4)!;
const solvedLines = linesOfAnswer(layout,answer)!;
console.log(withPortals(4,solvedLines.map(line=>[...line]),seededRandom(42),1,false));

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/tsunagi 1.7.0.