@ziagl/tiled-map-path-finder
Version:
A path finder library for 2 dimensional maps.
83 lines (82 loc) • 2.71 kB
TypeScript
import { CubeCoordinates } from 'honeycomb-grid';
export declare class PathFinder {
private readonly MAXLOOPS;
private _map;
private _map_columns;
private _map_rows;
private _map_layers;
private _grid;
private _hexSetting;
private _hexDefinition;
constructor(map: number[][], rows: number, columns: number);
/**
* computes path with lowest costs from start to end (A* algorithm)
* @param start start coordinates
* @param end end coordinates
* @param layerIndex layer index
* @returns path as cube coordinates or empty path if no path was found or layer is out of bounds
*/
computePath(start: CubeCoordinates, end: CubeCoordinates, layerIndex: number): CubeCoordinates[];
/**
* same as computePath, but with interface for offset coordinates
* @param start start coordinates
* @param end end coordinates
* @param layerIndex layer index
* @returns path as offset coordinates or empty path if no path was found or layer is out of bounds
*/
computePathOffsetCoordinates(start: {
x: number;
y: number;
}, end: {
x: number;
y: number;
}, layerIndex: number): {
x: number;
y: number;
}[];
/**
* returns all tiles that are in range
* @param start start coordinates
* @param maxcost maximum cost
* @param layerIndex layer index
* @returns reachable tiles as cube coordinates or empty path if layer is out of bounds
*/
reachableTiles(start: CubeCoordinates, maxcost: number, layerIndex: number): CubeCoordinates[];
/**
* Returns coordinates of all neighbors of a given base tile.
* Minimum 2 (map edges), maximum 6.
* @param base coordinates of a tile on this map
* @returns list of cubecoordinates of all neighbors
*/
neighborTiles(base: CubeCoordinates): CubeCoordinates[];
/**
* Converts cube coordinates to offset coordinates
* @param coordinate cube coordinates (q, r, s)
* @returns offset coordinates (x, y)
*/
cubeToOffset(coordinate: CubeCoordinates): {
x: number;
y: number;
};
/**
* Converts offset coordinates to cube coordinates
* @param coordinate offset coordinates (x, y)
* @returns cube coordinates (q, r, s)
*/
offsetToCube(coordinate: {
x: number;
y: number;
}): CubeCoordinates;
/**
* print map structured (one row as one line)
* @returns map as string
*/
print(): string;
/**
* print map unstructured
* @returns map as string
**/
print_unstructured(): string;
private calculateDistance;
private movementCosts;
}