0.1.1 • Published 9 years ago

js-pathfind v0.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

Javascript A* Pathfind

Javascript implementation of A* Pathfinding, developed for use with http://jsiso.com

Getting Started

This script is developed to work with Node.js and in the Browser.

Node

npm install js-pathfind
var Pathfind = require('js-pathfind');

Browser

<script type="text/javascript" src="build/pathfind.min.js"></script>
var Pathfind = window.Pathfind;

Pathfind

Pathfind(start, end, map);

start

Type: array Starting location x and y co-ordinate: x, y

end

Type: array Ending location x and y co-ordinate: x, y

Map

Type: array 2d array of any size which holds all the co-ordinates on the map. 0 = open square, 1 or above = blocked square x values = columns y values = rows (first row = 0)

Return

Type: array or boolean The returned value will be an array of co-ordinates showing the route through the map or false if not route is possible.

Example

var start = [0,0];
var end = [4,4];
var map = [
    [0, 0, 0, 1, 0],
    [1, 0, 0, 0, 1],
    [0, 0, 1, 0, 0],
    [0, 0, 1, 1, 0],
    [0, 0, 1, 1, 0]
];
var path = Pathfind(start, end, map);
console.log(path); // Output = [ [ 0, 0 ], [ 1, 1 ], [ 1, 2 ], [ 2, 3 ], [ 3, 4 ], [ 4, 4 ] ]

start = [0, 4]; // Start Bottom left
path = Pathfind(start, end, map);
console.log(path); // Output = false

License

MIT License 2013-2015 Edward Smyth

0.1.1

9 years ago

0.1.0

9 years ago