In this assignment, you are going to develop a Python program which simulates the driving of a computer controlled vehicle in Green Village. Question 1 – Roaming around the city Green Village is an...

In this assignment, you are going to develop a Python program which simulates the driving of a computer controlled vehicle in Green Village. Question 1 – Roaming around the city Green Village is an environmental friendly city surrounded by water. It has a size of 10001 units × 10001 units, where roads and houses in the city are organized in a grid structure (each grid is 1 unit × 1 unit). Driving in the city is easy, as the roads are either horizontal or vertical. Each grid in this city can be numbered with:  Row - from 0 to 10000 going along the West-East direction.  Column - from 0 to 10000 going along the South-North direction. To drive around the village, there are a number of driving commands for the computer controlled vehicle. The table below lists all four available operation commands: Operation commands Actions taken D Drives forward 1 grid cell. L Turns left in the current grid cell. It only changes the direction the vehicle faces, not really moving the vehicle. R Turns right in the current grid cell. X This marks the end of driving instructions. “Finished!” should be output and the program terminates. Driving rules To keep Green village a safe city, the rules below must be followed strictly: i Road safety:  The vehicle cannot cross the city edge.  It is alright to have the vehicle facing the city edge, just cannot move into or cross them. Write a Python program that allows a user to input the initial location of the vehicle and driving commands. When a command leads to an unsafe condition, an error message “Unsafe!” should be output and the program terminates. Input format The program first reads 3 values (Rs, Cs, and Fs) from user in the following format: Starting_location_and_direction:_Rs_Cs_Fs where _ = Space Rs = Row number of the vehicle's starting location p. 2 Cs = Column number of the vehicle's starting location Fs = Facing direction of the vehicle (N, E, S, W) at the starting location Then we will start to ask the user to input the allowed operation commands (i.e. D, L, R, X), one at a time, as in the following format (Note: _ is a space): Command:_D You may assume the input is always valid (e.g. no invalid command or invalid location/direction). Output format After getting each operation command, we will either output the current location in the following format: Current_location_and_direction:_Rd_Cd_Fd where _ = Space Rd = Row number of the vehicle's current location Cd = Column number of the vehicle's current location Fd = Facing direction of the vehicle (N, E, S, W) at the current location or we will output “Unsafe!” if the vehicle move into the city edge. To learn about the input, output and driving rules, check the test cases in the table below: Case Expected output (The highlighted texts are user input) 1. Starting location and direction: 0 0 N Command: D Current location and direction: 1 0 N Command: D Current location and direction: 2 0 N Command: R Current location and direction: 2 0 E Command: D Current location and direction: 2 1 E Command: X Finished 2. Starting location and direction: 100 100 E Command: D Current location and direction: 100 101 E Command: D Current location and direction: 100 102 E Command: L p. 3 Current location and direction: 100 102 N Command: D Current location and direction: 101 102 N Command: X Finished 3. Starting location and direction: 100 0 N Command: D Current location and direction: 101 0 N Command: L Current location and direction: 101 0 W Command: D Unsafe! 4. Starting location and direction: 0 10000 N Command: D Current location and direction: 1 10000 N Command: D Current location and direction: 2 10000 N Command: R Current location and direction: 2 10000 E Command: D Unsafe! Question 2 – Driving along the road Let’s now consider the road structure of Green Village. We present the location for roads and houses using the row and column numbers.  Main roads are located at row 0, 20, 40 and so on, and also column 0, 20, 40 and so on.  Minor roads are located at row (or column) 5, 10, 15, 25, 30, 35 and so on. A part of the city is shown below p. 4 In addition, we add a new driving command for user: Operation commands Actions taken F Drives forward to the next intersection. An intersection is the grid cell where a road (main or minor) crosses another road. Driving rules The driving rules has been updated to ensure vehicles are always on the road: i Restrictions on driving:  Driving is only allowed on main roads and minor roads.  Each road (main / minor) is bi-directional with driving directions indicated above. ii Road safety at other places:  The vehicle cannot cross the city edge or drive into any non-road area.  It is alright to have the vehicle facing a house (non-road area) or facing the city edge, just cannot move into or cross them. Write a driving simulator in Python that ensures the vehicle is always on the road. When a command leads to an unsafe condition, an error message “Unsafe!” should be output and the program terminates. To learn about the input, output and driving rules, check the test cases in the table below: Case Expected output (The highlighted texts are user input) 1. Starting location and direction: 50 50 N Command: F Current location and direction: 55 50 N Command: F p. 5 Current location and direction: 60 50 N Command: R Current location and direction: 60 50 E Command: F Current location and direction: 60 55 E Command: X Finished 2. Starting location and direction: 100 100 N Command: F Current location and direction: 105 100 N Command: R Current location and direction: 105 100 E Command: D Current location and direction: 105 101 E Command: R Current location and direction: 105 101 S Command: F Unsafe! Question 3 – Turning safety at intersection To avoid unfortunate traffic accident at intersections, Green Village require that when moving from a minor road to a main road, the vehicle cannot move to the right. The complete driving rules are presented as follows: i Restrictions on driving:  Driving is only allowed on main roads and minor roads.  Each road (main / minor) is bi-directional with driving directions indicated above. ii Road safety at an intersection:  When moving from a minor road to a main road, the vehicle cannot move to the right. It can only: 1) turn left and move; 2) doesn’t turn and move forward; 3) turn 180 degree and move forward, as the roads are all bi-directional.  No restrictions at other types of intersection (i.e. minor-to-minor, main-to-minor, main-to-main). iii Road safety at other places:  The vehicle cannot cross the city edge or drive into any non-road area.  It is alright to have the vehicle facing a house (non-road area) or facing the city edge, just cannot move into or cross them. Write a driving simulator in Python with above turning safety check. When a command leads to an unsafe condition, an error message “Unsafe!” should be output and the program terminates. To learn about the input, output and driving rules, check the test cases in the table below: p. 6 Case Expected output (The highlighted texts are user input) 1. Starting location and direction: 100 100 N Command: F Current location and direction: 105 100 N Command: R Current location and direction: 105 100 E Command: F Current location and direction: 105 105 E Command: F Current location and direction: 105 110 E Command: R Current location and direction: 105 110 S Command: F Current location and direction: 100 110 S Command: R Current location and direction: 100 110 W Command: F Unsafe! 2. Starting location and direction: 0 0 E Command: F Current location and direction: 0 5 E Command: L Current location and direction: 0 5 N Command: F Current location and direction: 5 5 N Command: R Current location and direction: 5 5 E Command: R Current location and direction: 5 5 S Command: D Current location and direction: 4 5 S Command: R Current location and direction: 4 5 W Command: R Current location and direction: 4 5 N Command: F p. 7 Current location and direction: 5 5 N Command: L Current location and direction: 5 5 W Command: F Current location and direction: 5 0 W Command: R Current location and direction: 5 0 N Command: D Unsafe!
Nov 10, 2020
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here