aStar

fun <T> aStar(from: T, to: T, neighbors: (T) -> List<T>, isWalkable: (T) -> Boolean, distance: (T, T) -> Int, movementCost: (T, T) -> Double): List<T>(source)

Applies the A* pathfinding algorithm on a given graph to find the shortest path from the start point from to the destination to.

Return

a list of points representing the shortest path from from to to based on the provided functions. Returns an empty list if no path is found.

Parameters

from

The starting point in the graph.

to

The destination point in the graph.

neighbors

A function that takes a point and returns a list of its neighboring points.

isWalkable

A function that takes a point and returns whether the point can be traversed or not.

distance

A function that estimates the distance between two points.

movementCost

A function that calculates the exact movement cost between two points. By default, it returns a constant cost of 1.0 for any pair of points or 0.0 if points are equal.


fun <T : PathTile<T>> aStar(from: T, to: T, neighbors: (T) -> List<T>): List<T>(source)

Applies the A* pathfinding algorithm on a given graph to find the shortest path from the start point from to the destination to.

Return

a list of points representing the shortest path from from to to based on the provided functions. Returns an empty list if no path is found.

Parameters

from

The starting point in the graph.

to

The destination point in the graph.

neighbors

A function that takes a point and returns a list of its neighboring points.