malwoden
Version:
   
49 lines (48 loc) • 1.89 kB
TypeScript
import { Vector2 } from "../struct";
import { TerrainCallback, IsBlockedCallback } from "./pathfinding-common";
interface AStarConfig {
isBlockedCallback?: IsBlockedCallback;
getTerrainCallback?: TerrainCallback;
topology: "four" | "eight";
}
/**
* AStar is a path finding algorithm that attempts search tiles closer
* the goal. It estimates a tiles score as the known distance to that
* tile, plus the distance to goal as the bird flies. It will always
* first evaluate the tile it knows to currently have the score,
* and continue from there.
*/
export declare class AStar {
readonly topology: "four" | "eight";
private readonly _isBlocked?;
private readonly _getTerrainCallback;
/**
* @param config - General parameters for the AStar Pathfinder
* @param config.isBlockedCallback - Return true if the position is blocked.
* @param config.getTerrainCallback - Provide terrain costs for movement (optional)
* @param config.topology - four | eight
*/
constructor(config: AStarConfig);
private getDistance;
/**
* Get all neightbors of a point. Returns orthogonal
* directions first, then diagonal if topology is 8.
* Results in more natural looking paths.
* @param pos - Vector2
*/
private getNeighbors;
private computePathBack;
/**
* Computes a given path from a start and end point. If not path is found,
* it will return undefined. Both the start + end points will be returned
* in the path.
*
* @param start Vector2 - The starting point
* @param end Vector2 - The ending point
*
* @returns RangeVector2[] | undefined - Returns the path,
* including start + end, or undefined if no path is found.
*/
compute(start: Vector2, end: Vector2): Vector2[] | undefined;
}
export {};