astar-core
Description
A-Star algorithm
Installation
npm install astar-core --save or yarn add astar-core
Usage
; const AStar Graph = AStarCore; // map size equals 【gridSize x gridSize】const gridSize = 10; // decide how many walls in mapconst wallFrequency = 01; // wall flagconst WALL = 0; // road flagconst ROAD = 1; // 2 D arrays to store all nodesconst nodes = ; // generate all nodes in mapfor let x = 0; x < gridSize; x++ const nodeRow = ; for let y = 0; y < gridSize; y++ const isWall = Math; if isWall === WALL nodeRow; else nodeRow; nodes; // start nodeconst start = nodes00; // end nodeconst end = nodesgridSize - 1gridSize - 1;// graph options// diagonal: specifies whether diagonal moves are allowed.const graphOptions = diagonal: false ; // create a map dataconst graph = nodes graphOptions; // a-star options// closest: specifies whether to return the path to the closest node if the target is unreachable.// heuristic: Heuristic function (see AStarCore.Heuristics).const astarOptions = closest: false heuristic: null ; // use a-star algorithm to search the shortest path.// it will return the path from start to end.const path = AStar;