@tamb/gamegrid
    Preparing search index...

    Function bfsFarthestStep

    • First step of a walk that ends on a cell as far from avoid as the board allows.

      Parameters

      • matrix: Cell[][]

        Board the walk is planned on.

      • isWalkable: IsWalkable

        Which cells may be entered.

      • from: Coord

        Start coordinate.

      • avoid: Coord

        Coordinate to move away from.

      Returns Direction | null

      The first direction, or null when no step exists.

      import { bfsFarthestStep, walkableUnlessTypes } from "@tamb/gamegrid/npc";

      const matrix = [
      [{ type: "wall" }, { type: "wall" }, { type: "wall" }, { type: "wall" }, { type: "wall" }],
      [{ type: "wall" }, { type: "floor" }, { type: "floor" }, { type: "floor" }, { type: "floor" }],
      [{ type: "wall" }, { type: "wall" }, { type: "wall" }, { type: "wall" }, { type: "wall" }],
      ];
      const isWalkable = walkableUnlessTypes(["wall"]);
      const away = bfsFarthestStep(matrix, isWalkable, [2, 1], [1, 1]);
      // "right". [4, 1] is the open cell farthest from the threat at [1, 1].