Board the walk is planned on.
Which cells may be entered. Also blocks cells the caller wants skipped.
Start coordinate.
Target coordinate.
The first direction, or null.
import { bfsNextStep, walkableUnlessTypes } from "@tamb/gamegrid/npc";
const matrix = [
[{ type: "wall" }, { type: "wall" }, { type: "wall" }],
[{ type: "wall" }, { type: "floor" }, { type: "floor" }],
[{ type: "wall" }, { type: "wall" }, { type: "wall" }],
];
const isWalkable = walkableUnlessTypes(["wall"]);
const toward = bfsNextStep(matrix, isWalkable, [1, 1], [2, 1]);
// "right"
import { bfsNextStep, walkableUnlessTypes } from "@tamb/gamegrid/npc";
const matrix = [
[{ type: "floor" }, { type: "floor" }, { type: "floor" }, { type: "wall" }, { type: "floor" }],
[{ type: "floor" }, { type: "wall" }, { type: "wall" }, { type: "wall" }, { type: "floor" }],
[{ type: "floor" }, { type: "floor" }, { type: "floor" }, { type: "floor" }, { type: "floor" }],
];
const isWalkable = walkableUnlessTypes(["wall"]);
const toward = bfsNextStep(matrix, isWalkable, [0, 0], [4, 0]);
// "down". The cells to the right dead-end, so the first step goes around.
First step of a shortest walk from
fromtoto. Returns null when the target is the start cell or no walk exists. Greedy axis steps are not used: beside a long wall they step toward the target and then reverse.