I am working on a problem, and i am having some difficulty starting it. If anyone has time , it would be greatly appreciated if they had a quick look at my code, and what i need to do. Here is what im trying to do:
a simulator program for a robot designed to move packages around in a warehouse environment.
The input to your program (from standard input) will contain a map of the environment in its original state, followed by a blank line, followed by a sequence of instructions to be performed by the robot.
The map specifies the size, shape and initial positions of all the packages in the environment, as well as the positions of the walls, and the initial position and orientation of the robot. The walls will be represented by the "star" character *. The robot will be represented by the characters ^, v, < or >, depending on which direction it is facing. There will be at most 26 "packages" in the environment, labeled with the letters A,B,C, etc. (note that packages may vary in size and shape).
The robot is capable of four basic operations, as follows:
L turn left
R turn right
F (try to) move forward
P print the state of the environment
The instructions for the robot will consist of an ordered sequence of these four basic instructions L,R,F,P enclosed in parentheses.
When it executes an L or R instruction, the robot remains in the same location and only its orientation changes. When it executes the F instruction, the robot attempts to move a single step in whichever direction it is facing.
If there is a package immediately in front of the robot when it tries to move forward, the package will move with the robot (in the same direction). If there are one or more packages immediately in front of that package, they will also move, as well the packages immediately in front of them, and so on. We assume the robot is strong enough to push any number of packages in front of it. Since the walls are immovable, however, there will be some situations where the robot tries to move forward but fails. This will happen if there is a wall immediately in front of the robot, or if there is a wall immediately in front of a package being pushed by the robot (either directly or indirectly). In these cases, the F instruction has no effect on the environment, and the robot continues to the next instruction. (Part of the challenge of the project is to determine which packages are being pushed, and whether or not a wall is being pushed.)
When a P instruction is executed, the current state of the environment should be printed, followed by a blank line. The robot leaves a trail behind it wherever it goes. So, when the environment is printed, places where there is no package or wall should be indicated by: a dot '.' if the robot has been there at some time during its path, and a blank space ' ' otherwise.
Attached is an exampleAttachment 6806
The environment might not be rectangular, but you may assume that it is entirely surrounded by walls, so there is no danger of the robot falling off the edge of the environment. Packages may have any shape, but you can assume that all characters belonging to a single package are contiguous (i.e. connected to each other). You may assume the environment is no larger than 80 x 80 (including walls) and that each package consists of no more than 128 characters. (Note: the program can be written to handle environments and packages of arbitrary size, but we do not force you to do so.)
Here is what i have done and where i need help:
Code:
#include <stdio.h>
#define ROBOT 26
#define WALL 27
#define NONE -1
#define MAX_ROWS 80
#define MAX_COLS 80
#define EAST 0
#define NORTH 1
#define WEST 2
#define SOUTH 3
void scan_state(
int *pnrows,
int ncols[MAX_ROWS],
int object[MAX_ROWS][MAX_COLS],
int *pdirection
);
void print_state(
int nrows,
int ncols[MAX_ROWS],
int object[MAX_ROWS][MAX_COLS],
int direction
);
int main( void )
{
int nrows; // number of rows in environment
int ncols[MAX_ROWS]; // number of columns in each row
int object[MAX_ROWS][MAX_COLS]; // object at each location
int direction; // which way the robot is facing
void scan_state(
int *pnrows,
int ncols[MAX_ROWS],
int object[MAX_ROWS][MAX_COLS],
int *pdirection
)
{
int ch;
int r,c;
r = 0;
c = -1;
while (( ch = getchar() ) != '(' ) {
c++;
if ( ch == '\n' ) {
ncols[r++] = c;
c = -1;
}
// else if { ...
// ... Not sure what goes in here ...
// }
}
*pnrows = r;
}
void print_state(
int nrows,
int ncols[MAX_ROWS],
int object[MAX_ROWS][MAX_COLS],
int direction
)
{
// need help here too plz
}
Thanks alot for your help.