GithubHelp home page GithubHelp logo

yj1438 / fast-astar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sbfkcel/fast-astar

0.0 0.0 0.0 381 KB

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

Home Page: https://sbfkcel.github.io/fast-astar

JavaScript 17.06% TypeScript 82.94%

fast-astar's Introduction

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';

const obj = require('../dist/index'),
    Grid = obj.Grid,
    Astar = obj.Astar;

// Create a grid
const grid = new Grid({
    col: 11,                  // col
    row: 7,                   // row
});

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

const { col, row, data } = grid;

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

console.log('Result', path);

/*
[
  [ 0, 3 ],  [ 1, 3 ],
  [ 2, 3 ],  [ 3, 4 ],
  [ 4, 5 ],  [ 5, 5 ],
  [ 6, 5 ],  [ 7, 5 ],
  [ 8, 4 ],  [ 9, 4 ],
  [ 10, 4 ]
]
*/

/*
0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 1 0 0 0 0 0 
2 2 2 0 0 1 0 0 0 0 0 
0 0 0 2 0 1 0 0 2 2 2 
0 0 0 0 2 2 2 2 0 0 0 
0 0 0 0 0 0 0 0 0 0 0
*/

Demo

Related

License

MIT

fast-astar's People

Contributors

sbfkcel avatar yj1438 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.