UNPKG

@evilkiwi/astar

Version:

Synchronous A* pathfinding for TypeScript

59 lines (52 loc) 1.81 kB
declare const diagonal: Heuristic; declare const manhattan: Heuristic; type Heuristic = (from: Vector, to: Vector) => number; type heuristics_Heuristic = Heuristic; declare const heuristics_diagonal: typeof diagonal; declare const heuristics_manhattan: typeof manhattan; declare namespace heuristics { export { heuristics_diagonal as diagonal, heuristics_manhattan as manhattan }; export type { heuristics_Heuristic as Heuristic }; } interface TileBuilder { elevation: number; isLegal?: boolean; validAsDestination?: boolean; } type TileBuilderCache = Omit<TileBuilder, 'isLegal'> & Required<Pick<TileBuilder, 'isLegal'>>; type Tile = TileBuilder | number; type Grid = Tile[][]; type Vector = [number, number]; interface Score { g: number; h: number; f: number; } type OpenTile = [Vector, Score, OpenTile | null]; interface ScoreOptions { current: Vector; parent: OpenTile; goal: Vector; heuristic: keyof typeof heuristics; } interface SearchOptions { from: Vector; to: Vector; grid: Grid; heuristic?: keyof typeof heuristics; diagonal?: boolean; cutCorners?: boolean; stepHeight?: number; } type Neighbor = [Vector, [Vector, Vector] | null]; declare function search(options: SearchOptions): Vector[] | null; declare function calculatePath(result: OpenTile): Vector[]; declare function neighbors(vector: Vector, diagonals?: boolean): { tiles: Neighbor[]; total: number; }; declare function score(options: ScoreOptions): Score; declare function vectorId(vector: Vector): string; declare function asc(a: number, b: number): 1 | -1 | 0; export { asc, calculatePath, neighbors, score, search, vectorId }; export type { Grid, Neighbor, OpenTile, Score, ScoreOptions, SearchOptions, Tile, TileBuilder, TileBuilderCache, Vector };