advp-2022 / maze_explorer

0 stars 4 forks source link

Maze solver

How to run the program?

This program uses pygame. To install the required dependencies, run:

$ pip install -r requirements.txt

Then you can run the code using:

python run.py

Customizing the default parameters

The program's default parameters are initialized in the file var.ini. You can change the colors, the screen size and the maze block size.

The program structure

In this program, a robot explores a maze to arrive at destination.

The maze generation code is located in the package lib.maze.

This code also contains two main classes inheriting from pygame.sprite.Sprite, the class Player and the class Target. They are both located in lib.player.

drawing

The main function contains the necessary routines to run the pygame window, to create instances of the Player and Target classes and to call the methods responsible for the movements.

We can use a movements matrix to record the visited neighbor:

The zeros in the neighbors_list corresponds to the empty cells (no walls), and the cells with value "1" are considered walls as illustrated in the figure below:

An example of a randomly generated maze is as follows:

drawing

In this case, the Player should move in a more intelligent way to reach the target. The end goal is to achieve the scenario in the animation shown above.

As it moves, the robot will always check for available moves using the function get_available_moves(). You can mark the already visited cells in the matrix as "-1", instead of "0" (empty cell) or "1" (Wall). This way, you can keep track of the cells you already visited. You can also use an array or list to store the visited positions.

TODO

List of things that need improvements or code refactoring

Code scalability

  1. Fix the GLOBAL_VAIRABLES issues.
  2. Make the algorithm work for any maze, even with loops:

    • Create a baseline maze with multiple loops
    • Generate random mazes with loops
    • Locate the problems in the current design
    • Try the greedy algorithm, the robot will start numbering the cases, and will restart the numbering at each location with multiple paths options.

Add-ons