However pathfinding.js is a little bloated, it comes with a collection of methods for path finding rather than just one tired yet true solution. It is also true that pathfinding.js no longer appears to be supported, which is not always such a bad thing mind you. It is true that if something is not broken there might very well not be a need to fix it after all, that sort of things happens now and then and that might very well be the case with pathinging.js.
Before getting into path finding I will first need some kind of Grid module. There are a bunch of ways of going about making this kind of module, however just about any gird module will consist of a 2d collection of objects in one form or another.
In this section I will be writing about my own js path fining solution that I put together after studying the source code of the PathFinding.js repository at github. I have not battle tested this, but the basic idea seems to work okay so far for what it is worth.
First off I need some kind of grid module, or at least decide on some kind of standard format for a grid. So then I worked out a module that will have a Class for what a single Node or tile if you prefer in a Grid, and of course a Grid class. I also worked out a number of other useful methods that I will want for this kind of module when it comes to making a path finding method of some kind. For example there is having a method that will return all of the nodes that border a given node which is an impotent first step for this sort of thing.
Here is the actual pathfinder module that I worked out bases very loosely on the AStarFinder method of pathfinding.js with many changes. The basic idea of any path finding method is to start at one node location of a grid, get the neighboring nodes, and then find which node would be the best option to move to next. This process is then repeated until a path to an end node is obtained or it is found that getting there is not possible.
So then I worked out some additional code to help with things like printing the state of a grid to the standard output of the console in a node project. In this library I am using my find path module to get an array of node positions for a set path, and then drawing that.
So now that I have my grid library and by path finder worked out I can now work out some examples that make use of it. So then I worked out a few test scripts to see if things work they way that they should more or less with this.
When I call this script form the command line I have a path from the start to end location. So it would seem that the module works okay. However I would want to do a fair amount of more testing, and I am not fully happy with how the source code looks. However I think that when it comes to really making this kind of project I will want to make it a little more front end friendly actually.
So then because this is a canvas project I often have a stand alone file for a few draw methods. I did not do much when it comes to this file for the project though, I just wanted a draw background method, and of course a method to draw the current state of a grid.
I am then testing out the get path method of the grid module right away, and using the returned path to set the fill style color of cells.
So then when this example is up and running I get a path of grid cells between that start and end cell locations of the grid. For the most path it would seem that the grid module works okay, but there are a few times where a weird path happens. My best guess as to what i could do to fix that would be to just try to get a better weight system that would be used to make choices as to what direction to go in. I could standard to do a little more testing, and I would like to work out some ore canvas examples that make use of this kind of system as a way to help make it a little more battle tested.