Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Solve this problem using Python: In Oman Robotics Competition, you are requested to design an NxN board to move your robot from the starting cell

Solve this problem using Python:

image text in transcribedimage text in transcribedimage text in transcribed

In Oman Robotics Competition, you are requested to design an NxN board to move your robot from the starting cell (represented by B) to a destination cell (represented by D) within the minimum number of moves in space cells (represented by S). You need to avoid the Obstacle cells (represented by *). The robot can start from any starting point cell A in any position (i,j), move only to space cells S until reaching one of the destination cells D. At a given time, the robot can move from the current position position (i,j) to one of four positions: position (i+1,j) "Down", position (i1,j) "Up", position (i,j+1) "Right", or position(i,j-1) "Left" as specified in the following figure, but it's not allowed to traverse obstacle cells. Write a Python program that reads the robotics board information from an input file, displays all the paths leading to existing destinations D in the robotics board, and specifies the shortest path from each starting cell B. The first line in the input file contains the size of the robotics board n ( nn matrix). The remaining n lines contains n cells separated by a single space. The coordinates of the board start from top to down (i=0n1) and from left to right (j=0n1). 1) Define a class to maintain the robotics board information including at least the following attributes and methods: a) An attribute to maintain the board size (N) b) An attribute as a 2D array to maintain the cells for the N by N board c) A constructor method and methods to get the values for all attributes. d) A methods readBoard(fName) to read the robotics board information from the specified file name, and maintain the board in a 2D array and set the values for the attributes. e) A method getAllStartingPoints() that returns the positions for all starting points (i, j). f) A method getAllPathfrom(i,j) that returns all paths from a given starting point at position (i,j) to all possible destinations g) A method getSHortestPathFrom (i,j) that returns the shortest path from a given starting point at position (i,j). You need to use a greedy algorithm strategy to avoid traversing all possible paths. 2) In the main function main(), you need to perform the following tasks: a) Define an object from RobotBoard and load the robotics board from the specific input file. b) Display the positions for all the possible starting point cells c) Repeatedly request from the user to specify the position for a starting point position (i,j) and perform the following tasks: i) Display an error message for invalid starting points and stop after entering position(-1,-1). ii) Display the paths from all starting point cell at position (i,j) to all possible destinations iii) Finds the shortest path from the specified starting point to the closest destination. Page 1 3) For getSHortestPathFrom(i,j) method, you need to discuss the strategy for the greedy algorithm and submit the corresponding flow chart for the method. 4) You may specify additional assumptions if needed. The following is a sample run for the first input file. Enter file name: Board1 . text The board is size is 88 There are 3 starting point cells: (0,1),(1,5),(4,4) Enter starting Point (i,j) : 01 When position (i,j)=(0,1) : There are 4 paths for the robotics Path 1:[(0,1),(1,1),(1,2),(2,2),(3,2),(3,3),(3,4)] path 2:[0,1),(1,1),(1,2),(2,2),(3,2),(3,2),(3,0),(2,0)] path 3:[(0,1),(1,1),(1,2),(2,2),(3,2),(4,2),(5,2),(6,2),(6,3),(6,4),(7,4)] path 4:[(0,1),(1,1),(1,2),(2,2),(3,2),(4,2),(5,2),(6,2),(6,3),(6,4),(6,5), (7,5),(7,4)] The shortest path of length 7 is [(0,1),(1,1),(1,2),(2,2),(3,2),(3,3),(3,4)] Enter Starting Point (i,j) : 11 Error: wrong initial location!! Enter Starting Point (i,j) : 11 ==END==

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

Students also viewed these Databases questions