A* Pathfinding library

What is it ?

This is a live demo from this library.

This library is another implementation in JavaScript of the famous A* algorithm. Special features are the support of toric maps (wrapped maps), JPS for uniform cost grids and multi-threading.

See it on GitHub for more informations.

It seems you're running this file from a local file system.
Cross origin requests may be supported only for protocol schemes on some browsers.

Diagonals
Cutting
Toric map
Heuristic
Profil
Scores
Jump Point Search
Map
                
        //Initialization
            let map = [], X = 0, Y = 0

        //Map generation
            for (let x = 0; x < X; x++) { map[x] = []
                for (let y = 0; y < Y; y++) {
                    //Returns a positive value for terrestrial biomes and negative for the aquatics ones
                        map[x][y] = biome(x, y)
                }
            }

        //Options
            let options = {
                order:"xy",
                diagonals:true,
                cutting:false,
                torus:false,
                heuristic:"euclidian",
                thread:false
            }

        //Create configuration
        //It's possible to define multiple layers with differents options/cost functions with a same map
        //Cost function returns the cost to go from node n to node m
            let astar = new Lowlight.Astar.Configuration(map,
                $.extend({cost(n, m) { return m >= 0 ? m : null }}, options), //Terrestrial
                $.extend({cost(n, m) { return m < 0 ? -m : null }}, options), //Aquatic
                $.extend({cost(n, m) { return Math.abs(m) }}, options) //All biomes types
            )

        //Path computing
            astar.path({x:0, y:0}, {x:0, y:0}, {
                callback(path, scores) { path.map(n => console.log(n)) },
                layer:0, //Terrestrial
                jps:false
            })