Question
Task 2: Suppose an autonomous vehicle can have the following three movements on a 10 by 10 grid network: turn right (R) turn left (L)
Task 2:
Suppose an autonomous vehicle can have the following three movements on a 10 by 10 grid network:
-
turn right (R)
-
turn left (L)
-
advance (A)
At any time, the vehicle can face one of the following four directions: north, east, south, and west. If the vehicle faces north, it will face east if it turns right. The vehicles location is given by a tuple (x, y), e.g., (3,8). As the vehicle moves towards east, x increases; as the vehicle moves towards north, y increases.
The vehicle receives and execute instructions. The analyst is interested in the vehicles location and in which direction it is pointing after the instructions are completed by the vehicle.
Here is a string of instructions sent to the vehicle, "RAALAL", which means:
o Turn right o Advance twice o Turn left o Advance once o Turn left
In this task, we assume that the vehicle starts at (7, 3) facing north. Then running this stream of instructions should leave it at (9, 4) facing west.
The vehicle movement can be interrupted in the following two cases:
There are two walls marked in red in Table 1, which prevent the autonomous vehicle from going through. If the vehicle attempts to go through the wall, the following message is printed:
Mission failed: vehicle crashed. The vehicle is not allowed to go beyond the 10 by 10 grid network. If the vehicle is out of the
network, the following message is printed:
Mission failed: out of boundary. You are asked to write a Python program to report the vehicle status after the vehicle has
received a series of instructions.
If the vehicle has successfully executed all instructions, print:
Mission completed: Location (xxx), Direction (yyy)
You should replace xxx and yyy with appropriate information.
In other cases, print either Mission failed: vehicle crashed. or Mission failed: out of boundary.
***
**BELOW IS MY CURRENT CODE, I NEED HELP SETTING UP THE RED WALLS AND OUT OF BOUNDS***
***
Table 4-1: The 10 by 10 grid network (1.10) (10,10) (1,9) (8,9) (1.8) (3.8) (1,7) (1,6) (1,5) (1.4) (5.5) (9,4) (1.3) (7.3) (8,3) (1.2) (2.2) (1,1) (2.1) (3,1) (4.1) (5,1) (6,1) (7.1) (8,1) (9.1) (101) N Wafe S Figure 4-2: Directions For testing purposes, assume input_instructions = ["RAALAL", "AALAARAAA", "RRAARA", "AAARALARA", "RRAAARA"). The following results should be printed: Instructions to be executed: RAALAL Results: Mission completed: Final Location (9.4) Final Direction: West 3 Instructions to be executed: AALAAAAA Results: Mission completed: Final Location (S. 8) Final Direction: North Instructions to be executed: RRARA Results: Mission completed: Final Location (6, 1) Final Direction: West Instructions to be executed: AAARALARA Results: Mission failed: vehicle crashed. Instructions to be executed: BRATARA Results: Mission failed: out of boundary. input_instructions - I "RAALAL", "AALAARAAA", "RRAARA", "AMARALARA", "RRASARA") #test instructions movements - I'A','1','R'] #different allowed movement for i in range(0, len(input instructions )): loop to run each string print('Instructions to be executed:, input_instructions[i]) #print which string its running (x,y) = (7,3) #initialization of x-coordinate and y-coordinate instruction - list(input_instructions[1]) fereates new list that splits string so it can run in the next for loop direction - North' initialization of direction for j in range(0, lon(instruction)) runs each character from string if instructions not in movements: tests to make sure its in the allowed movements print('I am confused!') #prints I am confused if not A.L.R. else: if instruction 1 -- 'A': If we are moving in North direction if direction - North': y+1 #y value will be incremented by 1 If we are moving in East direction elif direction="East": x+1 #x value will be incremented by 1 If we are moving in South direction elif direction="South": y-- Hy value will be decremented by 1 If we are moving in West direction elif direction"West": *x value will be decremented by 1 "If we encounter "Turn" or "Turn" if instruction (3) - 'L': if directions"North": direction"West" elif direction"West": direction "South elif direction-"South": direction="East" elif direction"East": direction-"North "Turn" case: if instruction - 'R': if direction"North": direction"East" elif direction"East": direction "South elif direction-"South": direction"West" elif direction"West": direction "North print('Results:') print("Mission Completed: Final Location', (x, y), 'Final Direction:', direction) Instructions to be executed: RAALAL Results: Mission Completed: Final Location (9, 4) Final Direction: West Instructions to be executed: AALAARAAA Results: Mission Completed: Final Location (5,8) Final Direction: North Instructions to be executed: RRAARA Results: Mission Completed: Final Location (6, 1) Final Direction: West Instructions to be executed: AAARALARA Results: Mission Completed: Pinal Location (9.7) Final Direction: East Instructions to be executed: RRAAARA Results: Mission Completed: Final Location (6, O) Final Direction: West Table 4-1: The 10 by 10 grid network (1.10) (10,10) (1,9) (8,9) (1.8) (3.8) (1,7) (1,6) (1,5) (1.4) (5.5) (9,4) (1.3) (7.3) (8,3) (1.2) (2.2) (1,1) (2.1) (3,1) (4.1) (5,1) (6,1) (7.1) (8,1) (9.1) (101) N Wafe S Figure 4-2: Directions For testing purposes, assume input_instructions = ["RAALAL", "AALAARAAA", "RRAARA", "AAARALARA", "RRAAARA"). The following results should be printed: Instructions to be executed: RAALAL Results: Mission completed: Final Location (9.4) Final Direction: West 3 Instructions to be executed: AALAAAAA Results: Mission completed: Final Location (S. 8) Final Direction: North Instructions to be executed: RRARA Results: Mission completed: Final Location (6, 1) Final Direction: West Instructions to be executed: AAARALARA Results: Mission failed: vehicle crashed. Instructions to be executed: BRATARA Results: Mission failed: out of boundary. input_instructions - I "RAALAL", "AALAARAAA", "RRAARA", "AMARALARA", "RRASARA") #test instructions movements - I'A','1','R'] #different allowed movement for i in range(0, len(input instructions )): loop to run each string print('Instructions to be executed:, input_instructions[i]) #print which string its running (x,y) = (7,3) #initialization of x-coordinate and y-coordinate instruction - list(input_instructions[1]) fereates new list that splits string so it can run in the next for loop direction - North' initialization of direction for j in range(0, lon(instruction)) runs each character from string if instructions not in movements: tests to make sure its in the allowed movements print('I am confused!') #prints I am confused if not A.L.R. else: if instruction 1 -- 'A': If we are moving in North direction if direction - North': y+1 #y value will be incremented by 1 If we are moving in East direction elif direction="East": x+1 #x value will be incremented by 1 If we are moving in South direction elif direction="South": y-- Hy value will be decremented by 1 If we are moving in West direction elif direction"West": *x value will be decremented by 1 "If we encounter "Turn" or "Turn" if instruction (3) - 'L': if directions"North": direction"West" elif direction"West": direction "South elif direction-"South": direction="East" elif direction"East": direction-"North "Turn" case: if instruction - 'R': if direction"North": direction"East" elif direction"East": direction "South elif direction-"South": direction"West" elif direction"West": direction "North print('Results:') print("Mission Completed: Final Location', (x, y), 'Final Direction:', direction) Instructions to be executed: RAALAL Results: Mission Completed: Final Location (9, 4) Final Direction: West Instructions to be executed: AALAARAAA Results: Mission Completed: Final Location (5,8) Final Direction: North Instructions to be executed: RRAARA Results: Mission Completed: Final Location (6, 1) Final Direction: West Instructions to be executed: AAARALARA Results: Mission Completed: Pinal Location (9.7) Final Direction: East Instructions to be executed: RRAAARA Results: Mission Completed: Final Location (6, O) Final Direction: WestStep 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