/pygame-pathfinder

Visualise maze creation & pathfinding algorithms with pygame

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

Pygame Pathfinder

Visualise maze generation and pathfinding algorithms with Pygame.

Installation

Clone this repo and cd into it:

git clone https://github.com/ChrisKneller/pygame-pathfinder.git
cd pygame-pathfinder

Create and activate your virtual environment:

  • MacOS/Linux:
virtualenv --no-site-packages env
source env/bin/activate
  • Windows:
virtualenv env
.\env\Scripts\activate

Install the required packages:

pip install -r requirements.txt

Usage

python grid.py

Buttons

Maze/terrain generation buttons are on the right.

Maze/terrain generation examples:

Prim's algorithm Recursive division Alternate Prim's algorithm Terrain generation

Pathfinding buttons are on the left.

Pathfinding examples:

Dijkstra's algorithm (equivalent to BFS in this case)

Dijkstra's algorithm

Depth first search (DFS)

DFS

A* algorithm

A*

The visualise button is a toggle.

Visualistation false

Grid interaction

Left click to create a wall or move the start and end points.

Hold left CTRL and left click to create a sticky mud patch (which reduces movement speed to 1/3).

The point of these mud patches is to showcase Dijkstra's algorithm (first) and A* (second) by adjusting the "distances" between the nodes:

Dijkstra on mud A* on mud

After a pathfinding algorithm has been run you can drag the start/end points around and see the visualisation update instantly for the new path using the algorithm that was last run.

Updating the path

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

GPL-3.0