Pathfinding Lab is a playground for pathfinding algorithms, made with plain JavaScript and the HTML5 canvas. In a garden of hedges and mud, four algorithms find the way from a mouse to a piece of cheese: breadth-first search, Dijkstra's algorithm, greedy best-first search and A*. It builds on the free pathfinding tutorial on spicyyoghurt.com.
This download gives you the complete project behind Pathfinding Lab. See how all the pieces fit together, or use the pathfinding code as a head start on a game of your own.
What's included:
- The complete code, fully commented and split into classes (JavaScript modules, no libraries or build tools)
- The pathfinding code in its own folder, without any drawing code, ready to use in your own game: the grid, the four algorithms, a binary heap (a fast priority queue), a random maze generator, path smoothing and flow fields
- Four modes, each in its own file: Search, Race, Chase and Swarm
- The images of the hedges, the mud, the grass, the mouse and the cats
- A settings file for the starting level, the options, the speeds and the colors
- A README and a license
The playground itself has:
- Breadth-first search, Dijkstra's algorithm, greedy best-first search and A*, one step at a time, showing the explored cells and the frontier (the cells it will check next)
- A race between all four algorithms on the same level
- A chase: the mouse runs to the cheese while cats hunt it down, and you draw hedges to keep them away
- A swarm of up to 500 mice that follows a flow field (a grid of arrows that point the way) to the cheese
- Hedges, mud and grass that you draw with a click or a tap, and a mouse and a piece of cheese that you can drag
- Random mazes, with as many extra openings as you like
- Three heuristics (Manhattan, Euclidean and octile), a heuristic weight, diagonal moves, corner cutting and path smoothing
- The cost of every cell, and an arrow pointing back to the cell the search came from, whenever you want to see them
- A button that copies your level as code
- A grid that fills the screen and stays sharp, from phone to desktop
What you can do with it:
You can use the code and the images in your own games and projects, including ones you sell. You don't have to credit us in your project. Just keep the short comment with our name at the top of each code file you use from this package. You can release your project anywhere, for example online or in an app store. Here's what you can't do:
- publish your project's source code, for example in a public repository, if it contains code from this package
- sell or share the code or the images from this package on their own, for example as an asset pack
- release Pathfinding Lab itself, unchanged or with only minor changes
LICENSE.txt in the zip has the full terms.
To run the project, you need a modern browser and a local web server, such as the Live Server extension for Visual Studio Code. The README explains how.
Want to learn how pathfinding works? The free tutorial walks you through it step by step, from breadth-first search to A* and flow fields: