UNPKG

@2d-game-grid/square

Version:
27 lines (26 loc) 1.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.listReachableCells = listReachableCells; const core_1 = require("@2d-game-grid/core"); /** * @param cell The start cell * @param maxPathSteps The maximum amount of steps (including) to a cell that should be returned (start and end cell included) * @param options The options to customize the pathfinding * @returns All cells that are reachable (excluding the start cell) */ function listReachableCells(cell, maxPathSteps, options) { const queue = new core_1.UniqueCellQueue(); const neighbors = cell.neighbors.list(core_1.ALL_DIRECTIONS); queue.ignore(cell); queue.addAll(neighbors); const reachableCells = []; while (queue.hasNext()) { const nextCell = queue.getNext(); const steps = cell.getPath(nextCell, options).length; if (steps >= 1 && steps <= maxPathSteps) { reachableCells.push(nextCell); queue.addAll(nextCell.neighbors.list(core_1.ALL_DIRECTIONS)); } } return reachableCells; }