Skip to content

One Python script for generating giant mazes, another for solving them (using the A* algorithm)

Notifications You must be signed in to change notification settings

tadeaspaule/make-and-solve-mazes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

make-and-solve-mazes

maze_maker.py

Generates a maze in the form of a black-and-white PNG image, with black being walls and white being walkways
The maze is surrounded by a 1-pixel-wide layer of black pixels (the outer walls), except for the entrance at the top and exit at the bottom

Passing size parameters:

maze_maker.py 300 100

Creates a 300x100 maze, saves as "300x100_n.png", where n is the first available positive integer
Without any parameters it creates a 400x400 maze

Creation process

  1. First creates the main path from entrance to exit
  2. Fills the remaining space with randomly branching paths
  3. Final cleaning, gets rid of unnecessary parts like 3x3 white squares, fills holes, etc

maze_solver.py

Solves a maze that's in a format like maze_maker makes, by converting the maze to a graph and using A* to search for the shortest path

Passing filename parameters:

maze_solver_.py 300x100_2.png

If you don't provide a filename, it tries to open 400x400_0.png by default. You can change this default in the script

Solving process

  1. Converts the maze to a graph
  2. This means junctions and turns are converted to graph nodes
  3. Uses the A* algorithm to find the shortest path

About

One Python script for generating giant mazes, another for solving them (using the A* algorithm)

Topics

Resources

Stars

Watchers

Forks

Languages