@ziagl/tiled-map-path-finder
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

tiled-map-path-finder

A path finding library for hexagon maps.

Sample images of usage in possible environment

This image shows how reachableTiles is used on a map with different tiles (tiles with different movement costs). In this example reachableTiles computes all tiles that can be reached with movement value of 6 (up to 6 tiles). Plain and Sand costs 1, Wood and Hills costs 2, Mountains are unpassable. Alt text

With computePath it is possible to find shortest (with the lowest costs) path. Alt text

It ignores tiles that are not passable. If no path is possible, it returns an empty path. Alt text

Sample code

const exampleMap:number [] = [
    1, 1, 2, 3,
    1, 2, 1, 3,
    2, 4, 8, 1,
    3, 1, 2, 1
];
const pf = new PathFinder(exampleMap, 4, 4);
const reachableTiles = pf.reachableTiles({q:0, r:0, s:0}, 2);
// reachableTiles.length is 7

Example usage of reachableTiles. It is important to initialize the component with a heatmap (a 2D map of all tiles used with movement value 0 -> not passable, >1 cost for passing). reachableTiles is called with a starting coordinate in cube coordinate system and a max cost value.

const exampleMap:number [] = [
    1, 1, 2, 3,
    1, 2, 1, 3,
    2, 4, 8, 1,
    3, 1, 2, 1
];
const pf = new PathFinder(exampleMap, 4, 4);
const path = pf.computePathOffsetCoordinates({x:0,y:0}, {x:3,y:3});
// path.length is 6

Example usage of computePath. Compute path is called with 2 cube coordinates for start and end. A second version computePathOffsetCoordinates does the same, but start and end can be passed as offset coordinates (normal x and y values in 2D space). It returns all tiles of shortest path.

Readme

Keywords

Package Sidebar

Install

npm i @ziagl/tiled-map-path-finder

Weekly Downloads

1

Version

1.0.3

License

GNU LESSER GENERAL PUBLIC LICENSE

Unpacked Size

69.4 kB

Total Files

15

Last publish

Collaborators

  • ziagl