This Python program demonstrates the A* algorithm for finding an optimal path in a randomly generated 2D matrix. The code is organized into three main files: distances.py, a_star.py, and main.py.
-
distances.py:
- Contains a
Functionsclass with methods for pathfinding-related functions. - Includes Manhattan and Euclidean distance calculations, along with a function to display a visual representation of a path on the matrix.
- Contains a
-
a_star.py:
- Implements the A* algorithm within the
AStarclass for pathfinding on a 2D matrix. - Utilizes the
Functionsclass fromdistances.pyfor distance calculations and path visualization.
- Implements the A* algorithm within the
-
main.py:
- The main program file where the user interacts with the application.
- Prompts the user for matrix dimensions, generates a random matrix with obstacles, and selects random start and goal positions.
- Allows the user to choose between Manhattan and Euclidean distances for path calculation.
- Uses the A* algorithm to find the optimal path and displays the matrix with the path on the console.
- Run
main.pyto execute the program. - Input the number of rows and columns for the matrix when prompted.
- The program generates a random matrix with obstacles and visually displays the optimal path using the A* algorithm.
- Choose between Manhattan and Euclidean distances for path calculation.
- The result, including the matrix with the path and key information, is printed on the console.
- Carlos Arroyo
- Gabriel Nassri
- Juan Carlos Estefanía