Reference · Rules, solvers and generation
withBridgesfunction
Lines that fill a board with want bridges made in them: where a line runs straight through a cell away from the edge
and two other lines each end on the cells either side of it the other way, those two are joined into one line over
the cell, which becomes a bridge. Null where they offer no place for them.
Import it
import { withBridges } from "@johnmorrisdotca/tsunagi";
Definition
function withBridges(size: number, lines: readonly number[][], random: Random, want: number): { paths: number[][]; bridges: Set<number>; } | null
Parameters
| Name | Type | Description |
|---|---|---|
size | number | The number of cells on each side of the board. |
lines | readonly number[][] | The lines that fill the board. |
random | Random | A reproducible random source returning values in [0,1). |
want | number | The requested number of bridges. |
Returns
{ paths: number[][]; bridges: Set<number>; } | null
The lines and the bridges, or null.
Examples
import { randomFilling, seededRandom, withBridges } from "@johnmorrisdotca/tsunagi";
const random = seededRandom(42);
const lines = randomFilling(6,random,12);
console.log(lines === null ? null : withBridges(6,lines,random,1));