Reference · Mazes, arrows and mixed boards
Gridtype
The native flat cell graph with geometry, neighbour sides, bounds and point-to-cell lookup.
Import it
import type { Grid } from "@johnmorrisdotca/meikyuu";
Definition
type Grid = {
readonly shape: MeikyuuShape;
readonly w: number;
readonly h: number;
readonly cells: number;
readonly centres: readonly Point[];
readonly sides: readonly (readonly Side[])[];
readonly neighbours: readonly (readonly number[])[];
readonly box: Box;
at(x: number, y: number): number;
};
Members
| Name | Type | Description |
|---|---|---|
shape | "square" | "circle" | "hex" | "triangle" | "heart" | "leaf" | "star" | "ring" | "diamond" | "cross" | "moon" | "hexagon" | "pyramid" | |
w | number | The two numbers the shape was asked for (columns and rows; rings; a radius). |
h | number | |
cells | number | |
centres | readonly Point[] | Where each cell's middle is. |
sides | readonly (readonly Side[])[] | Each cell's sides, one per wall round it, in the order the shape draws them. |
neighbours | readonly (readonly number[])[] | Each cell's neighbours across a side that is not the shape's edge. |
box | Box | The rectangle that holds the whole shape. |
at | (x: number, y: number): number | The cell at a point, or -1 where there is none. |
Examples
import type { Grid, MazeRecipe } from "@johnmorrisdotca/meikyuu";
import { buildMaze } from "@johnmorrisdotca/meikyuu";
const recipe: MazeRecipe = {shape:"square",w:5,h:5,algorithm:"backtracker",mode:"to-goal",seed:42};
const maze = buildMaze(recipe);
const grid = maze.grid;
const value: Grid = grid;
console.log(value);{
shape: 'square',
w: 5,
h: 5,
centres: [
[ 0.5, 0.5 ], [ 1.5, 0.5 ],
[ 2.5, 0.5 ], [ 3.5, 0.5 ],
[ 4.5, 0.5 ], [ 0.5, 1.5 ],
[ 1.5, 1.5 ], [ 2.5, 1.5 ],
[ 3.5, 1.5 ], [ 4.5, 1.5 ],
[ 0.5, 2.5 ], [ 1.5, 2.5 ],
[ 2.5, 2.5 ], [ 3.5, 2.5 ],
[ 4.5, 2.5 ], [ 0.5, 3.5 ],
[ 1.5, 3.5 ], [ 2.5, 3.5 ],
[ 3.5, 3.5 ], [ 4.5, 3.5 ],
[ 0.5, 4.5 ], [ 1.5, 4.5 ],
[ 2.5, 4.5 ], [ 3.5, 4.5 ],
[ 4.5, 4.5 ]
],
sides: [
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ],
[ [Object], [Object], [Object], [Object] ]
],
box: { x: 0, y: 0, w: 5, h: 5 },
at: [Function: at],
cells: 25,
neighbours: [
[ 1, 5 ], [ 2, 6, 0 ],
[ 3, 7, 1 ], [ 4, 8, 2 ],
[ 9, 3 ], [ 0, 6, 10 ],
[ 1, 7, 11, 5 ], [ 2, 8, 12, 6 ],
[ 3, 9, 13, 7 ], [ 4, 14, 8 ],
[ 5, 11, 15 ], [ 6, 12, 16, 10 ],
[ 7, 13, 17, 11 ], [ 8, 14, 18, 12 ],
[ 9, 19, 13 ], [ 10, 16, 20 ],
[ 11, 17, 21, 15 ], [ 12, 18, 22, 16 ],
[ 13, 19, 23, 17 ], [ 14, 24, 18 ],
[ 15, 21 ], [ 16, 22, 20 ],
[ 17, 23, 21 ], [ 18, 24, 22 ],
[ 19, 23 ]
]
}What it prints (run when this page was built)