Socket
Book a DemoInstallSign in
Socket

binos

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

binos

a-star pathfinder with weights

1.2.1
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

Binos

Simple a-star pathfinder.

Installation

npm install --save binos

API

const newMap = require('binos')([...nodes])

Function used to create a new map, nodes are an array of objects with the following fields:

FieldTypeDescription
xNumberX Coordinate.
yNumberY Coordinate.
weightNumberWeight of tile, ranging from 0 (best weight) to 1 (worst weight).

NOTE: A node with weight of 1 is unpassable.

const path = newMap(source, destination, options)

Function used to get the best path between source and destination within a Binos Map.

source & destination Field:

FieldTypeDescription
xNumberX Coordinate.
yNumberY Coordinate.

options

FieldTypeDescription
diagonalsBooleanIndicates whether moving diagonally is accepted or not, by default it is set to true.
calculateGNumberUsed to calculate the G of a A* Pathfinding Node. By default its the distance between the nodes being considered.

Example

'use strict'

const newMap = require('binos')

const getPath = newMap([
  { x: 0, y: 0, weight: 0.5 },
  { x: 1, y: 0, weight: 0.4 },
  { x: 2, y: 0, weight: 0.3 },
  { x: 3, y: 0, weight: 0.9 },
  { x: 4, y: 0, weight: 0.8 },
  { x: 0, y: 1, weight: 0.2 },
  { x: 1, y: 1, weight: 0.9 },
  { x: 2, y: 1, weight: 0.8 },
  { x: 3, y: 1, weight: 0.6 },
  { x: 4, y: 1, weight: 0.9 },
  { x: 0, y: 2, weight: 0.9 },
  { x: 1, y: 2, weight: 0.6 },
  { x: 2, y: 2, weight: 0.1 },
  { x: 3, y: 2, weight: 1 },
  { x: 4, y: 2, weight: 0.6 },
  { x: 0, y: 3, weight: 0.3 },
  { x: 1, y: 3, weight: 0.6 },
  { x: 2, y: 3, weight: 1 },
  { x: 3, y: 3, weight: 0.8 },
  { x: 4, y: 3, weight: 0.7 },
  { x: 0, y: 4, weight: 1 },
  { x: 1, y: 4, weight: 1 },
  { x: 2, y: 4, weight: 0.3 },
  { x: 3, y: 4, weight: 1 },
  { x: 4, y: 4, weight: 0 }
])

console.log(
  getPath({ x: 0, y: 0 }, { x: 4, y: 4 })
)

// => [
//   { x: 4, y: 4 },
//   { x: 3, y: 3 },
//   { x: 2, y: 2 },
//   { x: 1, y: 1 },
//   { x: 0, y: 0 }
// ]

Keywords

a

FAQs

Package last updated on 26 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.