Options
All
  • Public
  • Public/Protected
  • All
Menu

Represents a shortest path finder using the A Star algorithm.

See: https://en.wikipedia.org/wiki/A*_search_algorithm

It works for a 4 or 8 topology. The heuristic used is the Manhattan distance and the octile distance respectively.

const path = new AStar(
[
[0, 0, 0, 0, 1, 0],
[0, 1, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 0],
[0, 1, 0, 1, 1, 0]
],
{ type: 4 },
(c) => c === 1
);

path.init();

const result = path.search({ x: 0, y: 2 }, { x: 0, y: 5 });

console.log(result);

{
status: 'Success',
positions: [
{ x: 0, y: 2 }, { x: 0, y: 1 },
{ x: 0, y: 0 }, { x: 1, y: 0 },
{ x: 2, y: 0 }, { x: 2, y: 1 },
{ x: 2, y: 2 }, { x: 2, y: 3 },
{ x: 2, y: 4 }, { x: 2, y: 5 },
{ x: 1, y: 5 }, { x: 0, y: 5 }
]
}

Type parameters

  • T

    Any type of data.

Hierarchy

Index

Constructors

Methods

Constructors

  • Type parameters

    • T

      Any type of data.

    Parameters

    • grid: T[][]

      The grid for which to compute the path finding.

    • topology: Topology

      The topology of the grid.

    • blockCallbackFn: Path.BlockCallbackFn<T>

      A callback function used to determine if a cell is a blocking one.

    Returns AStar<T>

Methods

  • init(): void
  • Initializes the grid used to compute a path.

    A mandatory step before calling the search method.

    Returns void

Generated using TypeDoc