npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

byakugan-js

v0.1.3

Published

A simple implementation of A* Pathfinding algorithm for sensory type ninjas.

Downloads

32

Readme

Byakugan-js

NPM

Description

Byakugan-js is an array-based, super simple and lightweight implementation of A* pathfinding algorithm written in Typescript.

It's then compiled into JavaScript with ES 5 syntax.

The name Byakugan (白眼) was influenced by the manga series Naruto.

Demo: https://byakugan.js.org/ (please visit using either tablet or pc to see the demo).

Installation:

Node: npm install --save byakugan-js

Web: Use packages inside build/ or use one of the following CDNs:

Minified build:

<script src="https://cdn.jsdelivr.net/gh/rockmanvnx6/byakugan-js@master/dist/byakugan.min.js"></script>

Development build:

<script src="https://cdn.jsdelivr.net/gh/rockmanvnx6/byakugan-js@master/dist/byakugan.js"></script>

Quick start

Make sure Byakugan-js is installed via npm or included using CDN.

const Byakugan = require('byakugan-js'); // ignore if using CDN

const settings = {
        grid: [
            [1, 0, 0, 0],
            [1, 0, 0, 0],
            [0, 0, 0, 0],
            [0, 1, 0, 0],
            [0, 1, 1, 1],
            [0, 0, 0, 1],
        ],
        obstacles: [1,3], // Obstacle tiles
        diagonal: true, // Move diagonally, default false
}
const byakugan = new Byakugan(settings);
const paths = byakugan.search(0,1,3,3);

Methods:

search(row1, col1, row2, col2)

Return a 2D array which contains the coordinates of path.

Example:

let byakugan = new Byakugan(settings)
byakugan.search(0,1,3,3); // Find path from grid[0][1] to grid[3][3]

Return:

[ [1,1], [2,1], [2,2], [3,2], [3,3] ]

Settings Object

These are the available keys of the settings object

| Key | Value | | ---------------------------- | ------------------------------------------------------------ | | grid: Array<Array<Number>> | A 2D array describe the grid. Required | | obstacles: Array | Array of obstacles value. Default = [1] | | diagonal: boolean | true/false value to determine if the algorithm can go diagonally. Default = false | | callbacks: Object | An object contain list of callbacks functions. | | heuristics: Object | Select heuristic distance functions for type normal and diagonal. Use override to override the heuristic functions. |

Callbacks

These are the list of available callback functions:

| functions | description | | ------------------------- | ------------------------------------------------------------ | | nodeConstructions(node) | The function will be called after a node is constructed. It will pass a object type as the parameter the object will have the following values: { row: number, col: number, isObstacle: boolean} |

Heuristics

The available heuristic functions are:

  • Eucludian
  • Manhattan (default for normal (4 directions) movement)
  • Octile (default for diagonal (8 directions) movement)

The default settings were used based on this suggestions. Where for diagonal distance, Octile distance was chosen with D = 1 and D2 = sqrt(2).

To re-select/override a distance function, simply define in the settings object:

let settings = {
    grid: grid,
    heuristics: {
        normal: 'eucludian', // default Manhattan
        override: {
        	diagonal: function (a,b) {
                let dx = Math.abs(a.col - b.col);
                let dy = Math.abs(a.row - b.row);
                return 0.5 * (dx + dy)
            }
    	}
    }
}

The above configuration will use eucludian distance for normal movement and a custom function for diagonal movement.

Development guide:

  1. Fork or clone this project.
  2. Run cd byakugan/ && npm install
  3. Run npm run dev to develop
  4. Run npm run build to build
  5. Run npm run test or npm run coverage to test

Contribution

Contributions are very welcome. Simply fork this project and make pull requests.