Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Having a hard time writing beginner code for this Python3 exercise on recursive backtracking. Code which uses classes (and uses __init__, __repr__, etc. functions) would
Having a hard time writing beginner code for this Python3 exercise on recursive backtracking. Code which uses classes (and uses __init__, __repr__, etc. functions) would be greatly appreciated!
The input file above as text:
5 10 1 1 5 10 --------------------- | | | | |-+-+-+ +-+-+ + + +-| | | | | | | | +-+-+ + +-+-+-+ + | | | | | | | |-+-+ + + + +-+ +-+-| | | | |-+ +-+-+-+-+-+ +-+ | | | | | ---------------------
And the desired output, if there is a solution, should like this:
Thanks again for the help!
Use recursive backtracking to create a Python program that solves a maze. Use 2 functions for this program main()-gets filename through user input and opens the solver test() - runs a test on various mazes that would tell us if there is a solution, no solution, or that the maze makes the program fail Input In the main() function, an input file containing a maze is needed from the user when they are asked by the program. An empty string from the user will read "defmaze.txt", the default textfile. The program then checks if that file exists (if there's no solution, inform the user using a print statement that there is an error, and then stop the process). Format of maze file The input format begins with a single line giving the number of rows and columns that make up the maze (this example 5 rows and 10 columns). The input needs to also show whether a room is connected to an adjacent room or not. So, the input will also include additional columns and rows that contain walls ('-' and '|') that separate rooms or spaces that show 2 adjacent rooms are joined. An external boundary around the maze is also part of the input. The next 2 lines give the starting room and the ending room. Output The output for this program shows a path through a maze (this shall be shown using asterisks or *) or a message that informs the user that a clear path from the beginning to the end of the maze does not exist. Deliverables File(3) containing code used to solve the problem, and a program that tests the maze textfiles (which would print a message if a maze fails to work with the program) This is an example of a textfile that is provided for this exercise: 5 10 11 5 10 |-+-+-+ +-+-+ + + + ILI I +-+-+ + +-+-+-+ + I TIL || 1-+-+ + + + +-+ +-+- |-+ +-+-+-+-+-+ +-+ 5 10 11 5 10 - - - - - - - - - |-+-+-+ +-+-+ + + | | *| || | +-+-+ + +-+-+-+ + - | || + | |-+-+ + + + --- | |* * ** |- + +-+-+-+-+-+ +-+-| * * * +-+ | | --------------------- Use recursive backtracking to create a Python program that solves a maze. Use 2 functions for this program main()-gets filename through user input and opens the solver test() - runs a test on various mazes that would tell us if there is a solution, no solution, or that the maze makes the program fail Input In the main() function, an input file containing a maze is needed from the user when they are asked by the program. An empty string from the user will read "defmaze.txt", the default textfile. The program then checks if that file exists (if there's no solution, inform the user using a print statement that there is an error, and then stop the process). Format of maze file The input format begins with a single line giving the number of rows and columns that make up the maze (this example 5 rows and 10 columns). The input needs to also show whether a room is connected to an adjacent room or not. So, the input will also include additional columns and rows that contain walls ('-' and '|') that separate rooms or spaces that show 2 adjacent rooms are joined. An external boundary around the maze is also part of the input. The next 2 lines give the starting room and the ending room. Output The output for this program shows a path through a maze (this shall be shown using asterisks or *) or a message that informs the user that a clear path from the beginning to the end of the maze does not exist. Deliverables File(3) containing code used to solve the problem, and a program that tests the maze textfiles (which would print a message if a maze fails to work with the program) This is an example of a textfile that is provided for this exercise: 5 10 11 5 10 |-+-+-+ +-+-+ + + + ILI I +-+-+ + +-+-+-+ + I TIL || 1-+-+ + + + +-+ +-+- |-+ +-+-+-+-+-+ +-+ 5 10 11 5 10 - - - - - - - - - |-+-+-+ +-+-+ + + | | *| || | +-+-+ + +-+-+-+ + - | || + | |-+-+ + + + --- | |* * ** |- + +-+-+-+-+-+ +-+-| * * * +-+ | |Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started