Answered step by step
Verified Expert Solution
Question
1 Approved Answer
R2-D2 navigates the grid thanks to you but is now facing a more hostile grid, one with obstacles represented by 1s. Use the same assumptions
R2-D2 navigates the grid thanks to you but is now facing a more hostile grid, one with obstacles represented by 1s. Use the same assumptions provided in Q1 and return the length of the shortest path avoiding obstacles. Return -1 if no such path exists.
Hints: 1. Dont explore neighbors that dont exist (are beyond the grids boundary) 2. Dont explore neighbors that are obstacles. 3. Your search ends when there is nothing to explore.
grid = [[0,0,0], [1,1,0], [1,1,0]] start, goal = (0,1), (2,2) Solution = 4 grid = [[0,1], [1,01] start, goal = (0,0), (1,1) Solution = -1 ---> The R2-D2 can't travel diagonally and thus there doesn't exist any feasible path
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