Generates a Maze That Then Solves Itself using Python and Pygame

Generates a Maze That Then Solves Itself using Python and Pygame

Generates a maze that then solves itself using Python and Pygame. A Pygame program that generates a maze and solves itself using a Randomized DFS / Floodfill / Recursive Backtracking algorithm

Maze Generator And Solver

Program Purpose: Generates a maze that then solves itself

Language: Python and Pygame

Algorithm: Randomized DFS / Floodfill / Recursive Backtracking

Wikipedia Algorithm Pseudocode

How the program works

Generation

  1. Maintain a matrix that keeps track of visited cells
  2. Maintain a stack that keeps track of cells on the current path
  3. Start at the top left cell
  4. Randomly choose one of the available neighbor cells
  5. If there are none, go to previous cell in the stack
  6. Color visited cells blue, current cell blue, and remove the white wall
  7. Will eventually return to the top left cell and guarantees a maze

Solving

  1. Maintain a matrix that keeps track of visited cells
  2. Maintain a stack that keeps track of cells on the current path
  3. Start at the top left cell
  4. Randomly choose one of the available neighbor cells without a wall
  5. If there are none, go to previous cell in the stack
  6. Color visited cells green and current cell red
  7. Will eventually reach the bottom right cell, at which point the program restarts

Code Overview

  1. A matrix of cell classes: each cell instance maintains properties such as a wall array, visited / current booleans, and methods to draw to the screen
  2. Simulation Function
    1. Generation - Find next cell, check if it is inbounds and unvisited, remove the wall, move to that cell
    2. Solving - Find next cell, check if it is inbounds and unvisited, move to that cell

Install as executable file

Open the terminal / command line

pip install pyinstaller

Put maze.py inside of a folder called main (or whatever name you want)

Open up a terminal / command line inside the folder

pyinstaller --onefile -w maze.py

Go to dist and select main.exe

Download Details:

Author: joshualiu555 Download Link: Download The Source Code Official Website: https://github.com/joshualiu555/Maze-Generator-And-Solver License: MIT

python pygame game-development

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Mobile Game Development Company India, Game Developers in India

IndianAppDevelopers - As a Mobile game developers in India our 2D & 3D game developers build engaging 2D & 3D games for various mobile platforms. Hire our game developers now

Hire Python Developer | Python web development company india

Hire Python Developer from us for Scalable, Secure & Robust Python Web development Solutions. Strict NDA | 16+ Years Exp| 2500+ Clients| 450+ Experts

Best Python Development Company in USA | Python Development Services

We are a prominent Python development company in USA, offering affordable python development services for all Mobile & Web platforms to startups & enterprises of all sizes.

Hire Expert Python Developers | Hire Top Python Developers

For your custom Python development projects, hire our dedicated Python Developers on an hourly/full-time basis. We are experts in working with latest python frameworks.

Hire Python Developers

Are you looking for experienced, reliable, and qualified Python developers? If yes, you have reached the right place. At **[HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io")**, our full-stack Python development services...