1. Engineering
  2. Computer Science
  3. path finding search c hint vectorltvectorltintgtgt grid row vectorltintgtcol 0...

Question: path finding search c hint vectorltvectorltintgtgt grid row vectorltintgtcol 0...

Question details

Path finding Search C++

Each grid cell can be referred to by its row and column coordinates. Below is an 8 by 8 grid Row 0 Row 1 Row 2 Column 0 Column 2 Column 1 One grid cell is marked as the initial location (in blue), and another cell is marked as the goal location (in red). In this example, the starting location is (7,3) and the goal location is (2,6) Only four actions are allowed in this problem: move left by 1, move right by 1, move up by 1, and move down by 1. No diagonal movements are allowed You Al program should find a solution, which is a sequence of grid locations that leads the turtle from the start to the goal location. With the example above, one possible solution would be (7,3) (7,4) (7,5) (7,6) (6,6) (5,6) (4,6) (3,6) (2,6)

Part 1: Create a new Project-> Visual C++ -> Empty Project. Add a new C++ source file #include iostream» using nanespace std; int main() // add your code here cerr << endl; cout.flush system(pause); return e In order for your turtle code to work correctly with the environment, your program should, in order, Cin two numbers, which are the number of rows and the number of columns of the grid Cin two numbers, the row and column numbers of the starting location. Cin two numbers, the row and column numbers of the goal location. Cin one number, which is the number of obstacles in the grid. For each obstacle (in a loop): - Cin two numbers, the row and column numbers of the obstacle location Afterwards, the program should output the solution (a path for the turtle to take), using cout, in the following format. In this lab, it is fine that the path ignores obstacles. 1-1 row# column# row# column# row# column# row# column# row# column# row# column# row# column# this is exactly -1 (one space) -1 (endl)) (row number (one space) column number (endl)) 1-1 The numbers above should be the only things outputted using cout. If you have successfully completed part 1, your program should work with the environment.

Part 2: Continuing from Part 1, I would like to see that your program correctly records the grid that is sent to the program from the environment. cerr is similar to cout. However, when using the pathfinding environment, everything you output with cerr is sent to a log file For example, cerrO<s1sendl; will write O 1 to a log file in the same location as your exe file Your task: Output to the log file using cerr a representation of the grid after all the inputs are received, where 0 means an empty cell, 1 means the initial location, 2 means the goal location, and 3 means an obstacle. For example, for the following grid you should have in the log file: 00300 10300 00302 Make sure to end your main) function with cerr << endl; cout.flush0: system pause) return O

Hint: vector<vector<int>> grid

(row, vector<int>(col, 0))

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution