• Stars
    star
    139
  • Rank 262,954 (Top 6 %)
  • Language
    JavaScript
  • Created about 5 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

fast-astar is an implementation of a* algorithm using javascript. Small and fast.

fast-astar

fast-astar is an implementation of a* algorithm using javascript. Small and fast.

Use

Install fast-astar using npm or introduce Grid.js and Astar.js on the page

Install:

npm install fast-astar --save

Use:

import {Grid,Astar} from "fast-astar";

// Create a grid
let grid = new Grid({
        col:11,                  // col
        row:7,                   // row
        render:function(){       // Optional, this method is triggered when the grid point changes
            // console.log(this);
        }
    });

// Add obstacles to the grid
[[5,2],[5,3],[5,4]].forEach(item => {
    grid.set(item,'value',1);    // Values greater than 0 are obstacles
});

// Pass the grid as a parameter to the Astar object
let astar = new Astar(grid),
    path = astar.search(
        [2,3],                   // start
        [8,3],                   // end
        {                        // option
            rightAngle:false,    // default:false,Allow diagonal
            optimalResult:true   // default:true,In a few cases, the speed is slightly slower
        }
    );

console.log('Result',path);      // [[2,3],[3,2],[4,1],[5,1],[6,1],[7,2],[8,3]]

Demo

Related

License

MIT

More Repositories

1

towxml

微信小程序HTML、Markdown渲染库
JavaScript
2,503
star
2

WechatJumpGameHelper

基于Node.js的微信《跳一跳》辅助工具
JavaScript
93
star
3

puerts_cli

开箱即用的 PuerTS 脚手架工具。
JavaScript
40
star
4

pixi-apngAndGif

Let Pixi.js support apng, gif images. And allow control of its operation.
JavaScript
38
star
5

Gigabyte-Z490i-Intel-10700k-5700XT

Shell
38
star
6

markdown-server

Markdown的数学公式 `Lexte`,以及流程图`Mermaid`服务端渲染支持。
JavaScript
23
star
7

pixi-spine-debug

Show spine boundaries
JavaScript
14
star
8

qingwa

🐸 qingwa(Frog)—let node debug information display line number
JavaScript
4
star
9

ant-task

🐜 一个小巧且快速的脚本任务运行器。
JavaScript
3
star
10

iOS-Restrictions-Passcode

用于从iOS备份文件找回『访问限制密码』
JavaScript
3
star
11

PixiJS_Notes

Pixi.js学习笔记
CSS
3
star
12

lazyload

Loaded images of lazy loading components. Compatible with IE7 + browser.
JavaScript
3
star
13

WebGPU-NOTES

我的WebGPU学习笔记
TypeScript
1
star
14

fws

🦇FWS,Efficient and convenient front-end development workflow scaffolding
JavaScript
1
star
15

maze

迷宫地图生成算法
JavaScript
1
star
16

vcore

A base library for handling urls, element selectors, dom event bindings, and jsonp data requests.
TypeScript
1
star
17

youtubeDown

Youtube video download
JavaScript
1
star
18

typeof2

Very small and fast Javascript type acquisition method.
JavaScript
1
star
19

font-face-extract

用于提取html文件中有使用自定义字体 (WebFont) 的文字及对应字体的文件路径。
JavaScript
1
star