Answered step by step
Verified Expert Solution
Link Copied!

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 greatly appreciated!

image text in transcribed

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-+-+ + + + +-+ +-+- |-+ +-+-+-+-+-+ +-+ 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-+-+ + + + +-+ +-+- |-+ +-+-+-+-+-+ +-+

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions

Question

8. Do the organizations fringe benefits reflect diversity?

Answered: 1 week ago

Question

7. Do the organizations social activities reflect diversity?

Answered: 1 week ago