Giter Site home page Giter Site logo

astar's Introduction

@fabienjuif/astar

an A* algorithm in javascript

Installation

npm install --save @fabienjuif/astar

Usage

const getClosestPath = require('@fabienjuif/astar')

getClosestPath(
  // array of rows that contains cells
  graph,
  // starting cell { x, y }
  start,
  // ending cell { x, y }
  end,
  // all the rest of parameters are **not required**
  // but you can use them to tweak the engine
  ({
    // function to test two node are the same
    sameNode = defaultSameNode,
    // function that map the given graph to the one that the engine needs
    mapGraph = identity,
    // function to get neighbours of a cell (default works with squared cells)
    getNeighbours = defaultGetNeighbours,
    // function to get distance between 2 cells, default use pythagore (without the square root)
    distance = defaultDistance,
    // your heuristic
    heuristic = () => 1,
    // max loops before stoping the engine
    maxLoops = Infinity,
  } = {}),
)
  • Node are representated in object x, y
  • Graph is an array of cells
const graph = [
  // first line (x === 0)
  [0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5],
  // second line (x === 1)
  [1, 0], [1, 1], [1, 2],
  // third line (x === 2)
  [2, 0], [2, 1], [2, 2], [2, 3],[2, 4],[2, 5],
]

console.log(graph[2][3])

astar's People

Contributors

fabienjuif avatar

Stargazers

 avatar

Watchers

 avatar  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.