Reference · Pipes, rules and solving
Flowtype
Where the water is on a board as it is turned: the whole picture, from the pump outwards.
Import it
import type { Flow } from "@johnmorrisdotca/suido";
Definition
type Flow = {
wet: boolean[];
from: number[];
entry: number[];
depth: number[];
spills: {
cell: number;
side: number;
}[];
order: number[];
pieces: number;
wetPieces: number;
drains: number;
wetDrains: number;
solved: boolean;
};
Members
| Name | Type | Description |
|---|---|---|
wet | boolean[] | Whether the water has reached each cell. |
from | number[] | The cell the water came from into each wet cell; -1 for a source and for a dry cell. |
entry | number[] | The side each wet cell was entered on, the side facing |
depth | number[] | How many cells the water went through to get to each wet cell, 0 at a source; -1 for a dry cell. |
spills | { cell: number; side: number; }[] | Every opening of a wet piece that opens on nothing: the edge of the board, bare ground, or a piece that does not open back. The water runs out of each. |
order | number[] | The wet cells in the order the water reaches them, nearest the source first. |
pieces | number | How many pieces the board has, and how many of them are wet. |
wetPieces | number | |
drains | number | How many drains the board has, and how many are wet. |
wetDrains | number | |
solved | boolean | Whether the board is solved: the water reaches what its kind asks, and nothing runs out (and on an inlet-outlet board, it runs in one path). |
Examples
import { SUIDO_5X5 } from "@johnmorrisdotca/suido/levels-5x5";
import { decodeLayout, flowOf } from "@johnmorrisdotca/suido";
import { levelSolution } from "@johnmorrisdotca/suido/levels";
import type { Flow } from "@johnmorrisdotca/suido";
const row = SUIDO_5X5[0];
const code = row[0];
const layout = decodeLayout(code)!;
const solution = levelSolution(row)!;
const value: Flow = flowOf(layout,solution);
console.log(value);{
wet: [
true, true, true, true, true,
true, true, true, true, true,
true, true, true, true, true,
true, true, true, true, true,
true, true, true, true, true
],
from: [
-1, 0, 1, 2, 3, 0, 7, 8,
13, 14, 5, 10, 11, 12, 13, 10,
11, 16, 13, 14, 15, 20, 21, 22,
19
],
entry: [
-1, 3, 3, 3, 3, 0, 1, 1,
2, 2, 0, 3, 3, 3, 3, 0,
0, 3, 0, 0, 0, 3, 3, 3,
0
],
depth: [
0, 1, 2, 3, 4, 1, 8, 7,
6, 7, 2, 3, 4, 5, 6, 3,
4, 5, 6, 7, 4, 5, 6, 7,
8
],
spills: [],
order: [
0, 1, 5, 2, 10, 3, 11, 15,
4, 12, 16, 20, 13, 17, 21, 8,
14, 18, 22, 7, 9, 19, 23, 6,
24
],
pieces: 25,
wetPieces: 25,
drains: 7,
wetDrains: 7,
solved: true
}What it prints (run when this page was built)