From c73c52b91c9ed6812bdd93a63a05821fe255b3aa Mon Sep 17 00:00:00 2001 From: Krzysztof Rudnicki Date: Wed, 22 Mar 2023 11:14:38 +0100 Subject: [PATCH] feat: readme and ability to specify mazeFile name --- README.txt | 7 +++++++ main.py | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 README.txt diff --git a/README.txt b/README.txt new file mode 100644 index 00000000..aa1e675d --- /dev/null +++ b/README.txt @@ -0,0 +1,7 @@ +To run the program install python, go to project repository and just run python main.py: +python main.py + +you can specify the name of the file which stores maze by typing: +python main.py mazeFile.txt + + diff --git a/main.py b/main.py index ffb4cd2f..d3db04ed 100644 --- a/main.py +++ b/main.py @@ -26,6 +26,8 @@ Does not work if no path (Should print out NO PATH FOUND) import heapq +import sys + class MazeSolver: # self corresponds to "this" in js, it refers to object of MazeSolver class @@ -147,8 +149,12 @@ def print_maze(maze, path=None): # Ran first in the code if __name__ == '__main__': + print (sys.argv) + file_name = 'maze.txt' + if len(sys.argv) > 1: + file_name = sys.argv[1] # Open and load text file to array - maze = load_maze('mazes/mazeDeadEnd.txt') + maze = load_maze(file_name) # Initialize MazeSolver object with maze as paramater solver = MazeSolver(maze) # Find path using MazeSolver solve method