Please I need help with this Q Write a C program which wil

Please I need help : ( with this Q

Write a C program which will simulate robot movements in a maze. The maze has corridors and walls, and robot can move only in one of the four different directions: North, South, East, and West.

As an input you will be given a maze of rectangular shape divided into cells of fixed width. You are guaranteed that the maze will not exceed 60 × 60 dimensions. The maze will be given in the input, with a grid of characters ‘X’ and ‘.’, where ‘X’ denotes a wall and ‘.’ denotes an empty space.

The robot can move through empty spaces, but not through the wall. You can also assume that the robot cannot leave the maze; which is equivalent to the whole maze being surrounded by a wall.

After the maze you will be given the initial position of the robot with two numbers specifying row and column (the top left position is (1,1)). You will assume that the robot is

facing North (up on the maze grid). Following this, you will be given a sequence of commands consisting of letters, with possibly having whitespace between them. The letter commands are as follows:
R is a command to rotate the robot 90 degrees clockwise (to the right),

L is a command to rotate the robot 90 degrees counter-clockwise (to the left),
F moves the robot forward one cell, unless there is a wall preventing this, in which case the robot does nothing, and
Q denotes the final position. You should print out the current robot row, column, and orientation, and assume that the next test case follows. You will also print the original map with the letter ‘R’ being placed on all squares visited by the robot.

-------------------------------------------------------------------------------------------

Input

The input consists of several test cases. Each test case starts with a line with two integer numbers, r and c, where r is the number of rows and c is the number of columns. These numbers will be positive integers, except in the last line, which will be “0 0”, indicating the end of input.

After these numbers, there will be r lines describing the maze, each line corresponding to one row of cells. Each row of cells will contain a sequence of c characters describing the content of the cell. The X letter (‘X’) indicates a wall, and a dot character (‘.’) indicates an empty cell.

After the maze, the input will include two integers, which are the starting robot position, followed by the commands to move the robot. The commands consists of the letter commands specified earlier, with exactly one occurence of ‘Q’ at the end. The letter commands may be broken by arbitrary whitespaces.

Output

You program must print the final row, column, and orientation of the robot for each test case, followed by the map of robot movements. The orientation is denoted as N (for North or up), S (for South or down), E (for East or left), and W (for West or right). The map that follows should have the letter ‘R’ placed in all squares visited by the robot.

-------------------------------------------------------------------------------------------------

Sample Input

2 2

..

..

1 1

RFRFQ

7 8

XXXXXXXX

X.X.X.XX

X.X....X

X.X.XX.X

X.X.X..X

X...X.XX

XXXXXXXX

2 4

RRFLFF FFR

FF

RFFQ

0 0

Sample Output

2 2 S

RR

.R

5 6 W

XXXXXXXX

X.XRX.XX

X.XRRRRX

X.X.XXRX

X.X.XRRX

X...X.XX

XXXXXXXX

Solution

#include <iostream>

using namespace std;

class Robot
{
public:
int x;
int y;
int dir = 0;

char get_dir()
{
switch (dir)
{
case 0:
return \'N\';
case 1:
return \'W\';
case 2:
return \'S\';
case 3:
return \'E\';
}
}

void get_status()
{
cout << x << \' \' << y << \' \' << get_dir() << endl;
}

void move(char maze[62][62], int r, int c)
{
int op;
if (dir < 2)
op = -1;
else
op = 1;

if (dir % 2 == 1)
if (x < c && x > 1 && maze[y][x + op] == \'.\')
x += op;

else
if(y < r && y > 1 && maze[y + op][x] == \'.\')
y += op;
}

void turn(char where)
{
if (where == \'L\')
dir = ++dir % 4;
if (where == \'R\')
dir = --dir % 4;
}

void wtf(char what, char maze[62][62], int r, int c)
{

if (what == \'Q\')
get_status();
else if (what == \'F\')
move(maze, r, c);
else
turn(what);
}
};


int main()
{

int r, c;
cin >> r >> c;
while (r != 0 && c != 0)
{


Robot pepito;
char omgjsuislost[62][62];

for (int i = 1; i <= r; i++)
for (int j = 1; j <= c; j++)
cin >> omgjsuislost[i][j];

cin >> pepito.x >> pepito.y;

char dequosser = \' \';
while (dequosser != \'Q\')
{
cin >> dequosser;
pepito.wtf(dequosser, omgjsuislost, r, c);
}

cin >> r >> c;
}

return 0;
}

Please I need help : ( with this Q Write a C program which will simulate robot movements in a maze. The maze has corridors and walls, and robot can move only in
Please I need help : ( with this Q Write a C program which will simulate robot movements in a maze. The maze has corridors and walls, and robot can move only in
Please I need help : ( with this Q Write a C program which will simulate robot movements in a maze. The maze has corridors and walls, and robot can move only in
Please I need help : ( with this Q Write a C program which will simulate robot movements in a maze. The maze has corridors and walls, and robot can move only in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site