bgrins/javascript-astar
bgrins/javascript-astar has 1,395 GitHub stars and 315 forks. GitHot measured 0 stars in 24 hours, -1 in 7 days, and +3 in 15 days. Last checked 2026-11-23 10:29 UTC. Last push 2023-09-04.
측정된 스타 증가
- in 24h
- 0
- in 7 days
- -1
- in 15 days
- +3
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
소개
JavaScript로 구현한 A* 탐색 및 경로 찾기 알고리즘
개발 도구README.md
Originaljavascript-astar
An implementation of the A* Search Algorithm in JavaScript
See a demo at http://www.briangrinstead.com/files/astar/
Sample Usage
If you want just the A* search code (not the demo visualization), use code like this http://gist.github.com/581352
<script type='text/javascript' src='astar.js'></script>
<script type='text/javascript'>
var graph = new Graph([
[1,1,1,1],
[0,1,1,0],
[0,0,1,1]
]);
var start = graph.grid[0][0];
var end = graph.grid[1][2];
var result = astar.search(graph, start, end);
// result is an array containing the shortest path
var graphDiagonal = new Graph([
[1,1,1,1],
[0,1,1,0],
[0,0,1,1]
], { diagonal: true });
var start = graphDiagonal.grid[0][0];
var end = graphDiagonal.grid[1][2];
var resultWithDiagonals = astar.search(graphDiagonal, start, end, { heuristic: astar.heuristics.diagonal });
// Weight can easily be added by increasing the values within the graph, and where 0 is infinite (a wall)
var graphWithWeight = new Graph([
[1,1,2,30],
[0,4,1.3,0],
[0,0,5,1]
]);
var startWithWeight = graphWithWeight.grid[0][0];
var endWithWeight = graphWithWeight.grid[1][2];
var resultWithWeight = astar.search(graphWithWeight, startWithWeight, endWithWeight);
// resultWithWeight is an array containing the shortest path taking into account the weight of a node
</script>
A few notes about weight values:
- A weight of 0 denotes a wall.
- A weight cannot be negative.
- A weight cannot be between 0 and 1 (exclusive).
- A weight can contain decimal values (greater than 1).
Original (slower) implementation
The original version of the algorithm used a list, and was a bit clearer but much slower. It was based off the original blog post. The code is available at: https://github.com/bgrins/javascript-astar/tree/0.0.1/original-implementation.
The newest version of the algorithm using a Binary Heap. It is quite faster than the original. http://www.briangrinstead.com/blog/astar-search-algorithm-in-javascript-updated Binary Heap taken from http://eloquentjavascript.net/appendix2.html (license: http://creativecommons.org/licenses/by/3.0/)
Running the test suite
If you don't have grunt installed, follow the grunt getting started guide first.
Pull down the project, then run:
npm install
grunt
관련 프로젝트 살펴보기
불러오는 중…
