hexr-pathfinder

1.1.0 • Public • Published

Hexr-Pathfinder

Good news: This is a fairly clean implementation of A* in javascript. It runs in its own thread care of Web Workers.

Bad news: It only works on a custom type of node graph that is generated by the Hexr-Editor (which isn't open source or publically available at all).

It assumes that you've done the hard work of taking a tile map and turning it into a node graph of waypoints. It has some serious limitations because it's waypoints rather than a grid. Whilst the code does a pretty good job of inserting start nodes and end nodes where it can (on the assumption that it'd be pretty rare for waypoints to align exactly with points of interest in the map), the code does need these start and end co-ordinates to be vertically aligned with waypoints.

Why are you bothering to publish this if it's useless to anyone else?

Hey, got to put some documentation somewhere!

var generatePathfinder = require('hexr-pathfinder');

var pathfinder = generatePathfinder();

pathfinder.setCurrentNodeGraph(nodeGraph, function (err, nodeCount){
		
	if (!err){
		// woo we're ready to go!
		pathfinder.findRoute({x : 0, y : 0}, {x : 45, 78}, function (err, route){
			if (!err){
				// route === [{x : 0, y : 0, type : 'start'}, { x: 10, y : 0, type : 'walk'}, {x : 12, y : 4, type : 'jump'}, ... ]
			}
		})
	}

});

The Node Graph

I mean, who knows, maybe someone will actually want to use this? Here's what the pathfinder expects: It's an array of nodes, with the following structure:

[
	{
		position : { // pretty obvious what this is
			x : 0,
			y : 0
		},
		connections : [
			{
				type : 'walk',  // actually the code doesn't care about this, but it makes sure it's in the generated route
								// for the use of your local solver
				cost : 10		// this is your movement cost for the A* algorithm
				node : 1		// this is the id of the node that you're pointing at
			}
		],
		id : 0 // every node needs an ID
	},
	{
		position : {
			x : 10,
			y : 0
		},
		connections : [
			{
				type : 'jump',
				cost : 6,
				node : 2
			}
		],
		id : 1
	},
	// ... 
]

No idea what the performance of this is like. It runs in its own thread and the particular application I have for it isn't high priority AI anyway so who knows.

License

MIT? What the hell. This is useless to everyone except me.

## Contributing

You probably shouldn't.

Readme

Keywords

none

Package Sidebar

Install

npm i hexr-pathfinder

Weekly Downloads

1

Version

1.1.0

License

MIT

Last publish

Collaborators

  • charlottegore