A simple python visualizer for different algorithm in a 2d grid. Including Breath First Search, Depth First Search, Greedy Best First Search, A Star, Iterative Deepening Depth First Search, and Hill Climbing Search.
To use this program, we need to use a DOS command-line interface and execute the scripts. We need to go to the directory and type python search.py . Notice that the method is in short form to save time by not needing to type in full form and it is not case-sensitive. It is listed below.
| Full form | Short form |
|---|---|
| Breath First Search | bfs |
| Depth First Search | dfs |
| Greedy Best First Search | gbfs |
| A Star Search | as |
| Iterative Deepening Depth First Search | iddfs |
| Hill Climbing Search | hc |
For example, if I want to execute an environment txt file that is in the same directory as the scripts name “RobotNav-test.txt” with Breath First Search. I will need to go to the directory and type python search.py RobotNav-test.txt bfs then execute it in the DOS command-line interface
After execution, two things will appear. First, you will get an output in the terminal and a GUI display in the window.
When a goal can be reached, the output will be:
filename method
goal number_of_nodes
path
When a goal can not be reached, the output will be:
filename method
No goal is reachable; number_of_nodes
With the exception of Iterative Deepening Depth First Search because it will also display the depth it went.
For the GUI, it will display a grid with the text file in blocks. Different color blocks represents different things.
| Color | Meaning |
|---|---|
| White | The block is a path that can be reached |
| Deep Gray | The block is a wall that can not be reached |
| Green | The block is a goal that can be reached and will end the search once reached |
| Light Gray | The block is in the visited list, meaning the search algorithm once visited that node |
| Blue | The block is in the path list, meaning the search algorithm needs to visit that node to get to the goal |
| Red | The block is the starting point |
The GUI will first display the grid that has goals, walls, and starting points. Then the GUI will
showcase the visited list that the search algorithm visited. Finally, if the search algorithm
finds a path, it will stop visiting nodes and show the path to get to the goal. NOTICE THAT
PATH WON’T BE DRAWN IF THERE IS NO SOLUTION.
(if the display is too fast, we can change the delay number in the drawgui class. The
higher the number is, the slower the block draws.)
