Write a function maze runner (maze, start, exit) that takes three inputs: maze (a 2-dimensional matrix...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a function maze runner (maze, start, exit) that takes three inputs: maze (a 2-dimensional matrix representing a maze, a nested list) and start and exit coordinates (the x and y coordinates where the maze runner starts and where the runner should finish, a tuple containing 2 integers). The maze is filled with numbers indicating different environments: "0" is a safe area the runner can go on. "1" is a hostile area or blocked area that the runner cannot go to. The function returns True if the runner can escape, else return False. Maze search is actually a difficult task. To simplify, there will always be one path from start to end if it exists. For example, we have a 4x4 maze = [[0, 1, 1, 1], [0, 0, 1, 0], [1, 0, 1, 1], [1, 0, 0, 0]] and start = (0, 0) and exit = (3, 3), then we have: 1. visit the start and check other locations to go: visited = [(0, 0)], unvisited = [(1, 0)] 2. visit the next unvisited location: visited = [(0, 0), (1, 0)], unvisited = [(1, 1)] 3. visit the next unvisited location: visited = [(0, 0), (1, 0), (1, 1)], unvisited = [(2, 1)] 4. visit the next unvisited location: visited = [(0, 0), (1, 0), (1, 1), (2, 1)], unvisited = [(3, 1)] 5. visit the next unvisited location: visited = [(0, 0), (1, 0), (1, 1), (2, 1), (3, 1)], unvisited = [(3,2)] 6. visit the next unvisited location: visited = [(0, 0), (1, 0), (1, 1), (2, 1), (3, 1), (3,2)], unvisited = [(3, 3)] 7. the next visiting location is the exit, so return True However, if the start is (1, 3) from the above example, there is no path to the exit, so it would return False. Note: The runner will always spawn at a safe location (i.e., 0), same for the exit, and they will never be at the same location. Note 2: the maze will always be a square (the number of rows and columns are the same). Hint: you need to keep track of both visited and unvisited locations. For example: Test Result maze[[0, 1, 1, 1], True [0, 0, 1, 0], [1, 0, 1, 1], [1, 0, 0, 0]] start = (0, 0) exit = (3, 3) print(maze runner (maze, start, exit)) Write a function maze runner (maze, start, exit) that takes three inputs: maze (a 2-dimensional matrix representing a maze, a nested list) and start and exit coordinates (the x and y coordinates where the maze runner starts and where the runner should finish, a tuple containing 2 integers). The maze is filled with numbers indicating different environments: "0" is a safe area the runner can go on. "1" is a hostile area or blocked area that the runner cannot go to. The function returns True if the runner can escape, else return False. Maze search is actually a difficult task. To simplify, there will always be one path from start to end if it exists. For example, we have a 4x4 maze = [[0, 1, 1, 1], [0, 0, 1, 0], [1, 0, 1, 1], [1, 0, 0, 0]] and start = (0, 0) and exit = (3, 3), then we have: 1. visit the start and check other locations to go: visited = [(0, 0)], unvisited = [(1, 0)] 2. visit the next unvisited location: visited = [(0, 0), (1, 0)], unvisited = [(1, 1)] 3. visit the next unvisited location: visited = [(0, 0), (1, 0), (1, 1)], unvisited = [(2, 1)] 4. visit the next unvisited location: visited = [(0, 0), (1, 0), (1, 1), (2, 1)], unvisited = [(3, 1)] 5. visit the next unvisited location: visited = [(0, 0), (1, 0), (1, 1), (2, 1), (3, 1)], unvisited = [(3,2)] 6. visit the next unvisited location: visited = [(0, 0), (1, 0), (1, 1), (2, 1), (3, 1), (3,2)], unvisited = [(3, 3)] 7. the next visiting location is the exit, so return True However, if the start is (1, 3) from the above example, there is no path to the exit, so it would return False. Note: The runner will always spawn at a safe location (i.e., 0), same for the exit, and they will never be at the same location. Note 2: the maze will always be a square (the number of rows and columns are the same). Hint: you need to keep track of both visited and unvisited locations. For example: Test Result maze[[0, 1, 1, 1], True [0, 0, 1, 0], [1, 0, 1, 1], [1, 0, 0, 0]] start = (0, 0) exit = (3, 3) print(maze runner (maze, start, exit))
Expert Answer:
Answer rating: 100% (QA)
Heres a Python function mazerunner that implements th... View the full answer
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Posted Date:
Students also viewed these programming questions
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
International Markets Project You have been hired as a globalization specialist by Kwik-E-Mart. Kwik-E-Mart is a large retailer that has outgrown its domestic market and seeks to expand its...
-
Determine values for the constants n and k (Equation 10.17) for the crystallization of polypropylene (Figure 15.17) at 160C.
-
Under a single rate consumption-style VAT, which method of calculating tax liability is the best if a nation wants to exempt specific commodities, such as unprocessed food or medical drugs? Does the...
-
What would you expect the nominal rate of interest of German government bonds to be if the real rate is 6 percent and the expected inflation rate is 9 percent?
-
Buhl Corp. sponsors a defined benefit pension plan for its employees. On January 1, 2014, the following balances relate to this plan. Plan assets ......... $480,000 Defined benefit obligation ......
-
7. The full symbol of an ion of an element is 39X+? Which one of the following is the number of electrons in the ion? A. 18 B. 19 C. 20 D. 39 8. The atomic numbers of elements W, X, Y and Z are 9,...
-
1) Consider the following three coupled equations: Identify all of the matrix equations from the list below that are equivalent to this system of equations above: 3 4 069-0 a) y. -2 3 2 -1. b) x + 3y...
-
An industry faces an inverse demand curve given by: P = 90 - 1.5Q. Let MC = 0.5Q before a new environmental-protection regulation and MC=10 + 0.5Q after the regulation. Determine a) The cost to...
-
1. You want to build a CRR binomial model to value options on Moderna (MRNA). The current stock price of MRNA is 310.20. Assume the volatility of MRNA is 61.2% (annual) and the risk-free interest...
-
Calculate the Free Cash Flow (FCF) for this company. Income statement, year ended December 31, 2021 (in millions of US dollars, except per share amounts) Sales Net sales Cost of goods sold Gross...
-
Compare the average profit per program based on the scenarios as follows: Scenario Summary report using the average profit per program (range B10:F10 ) as the result cells to show how the average...
-
Macroware Corporation reported the following information in its financial statements for three successive quarters ($ in millions): Balance Sheets: 6/30/2020 (Q4) Three Months Ended 3/31/2020 (Q3)...
-
Assume that you are a CEO of a medium-sized company that needs a significant influx of cash for several expansion projects. As the CEO, you must determine whether your company should remain private...
-
Research an article from an online source, such as The Economist, Wall Street Journal, Journal of Economic Perspectives, American Journal of Agricultural Economics, or another academic journal. The...
-
Light of a single wavelength is incident on a diffraction grating with \(500 \mathrm{slits} / \mathrm{mm}\). Several bright fringes are observed on a screen behind the grating, including one at...
-
The shiny surface of a CD is imprinted with millions of tiny pits, arranged in a pattern of thousands of essentially concentric circles that act like a reflection grating when light shines on them....
-
If sunlight shines straight onto a peacock feather, the feather appears bright blue when viewed from \(15^{\circ}\) on either side of the incident beam of sunlight. The blue color is due to...
Study smarter with the SolutionInn App