473,394 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

I need help Urgently.

I have got a homework task to do and I have started the work but I cannot finish it.Can someone please help me finish the code. The help given is much appreciated.


The actual specifications are here:

The task for this project is to write 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.

For example, given this 9-line input:

**************
********** *
* * BB *
* A *
* *** AA * *
* ^ A * *
************************

(FFFFFRFFFLFRFFFFRFFPLFFFRFRFFFFFFFFFFFFFP)

your program should produce the following 16-line output:
**************
********** ..... *
* ....* v *
* . A BB *
* *** . AA * *
* . A * *
************************

**************
********** ..... *
* ....* .... *
* ABB<........... *
* ***AA . * *
* A . * *
************************


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.)



This is the actual file we need to implement. They have provided the template, we need to fill in the blanks.



/** \file homework.c

Modify this code to scan the state of the environment,
as specified in Homework Sheet 2, and print this state to standard output.


*/

#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

// scan the state of the environment
scan_state( &nrows, ncols, object,&direction );

// print the state of the environment
print_state( nrows, ncols, object, direction );

return 0;
}

/**
Scan the state of the environment from standard input.

The two-dimensional array object[][] is used
to return a map of the environment;<br>
if there is a package at location (r,c) then
object[r][c] will be an integer between
0 (representing 'A') and 25 (representing 'Z');
otherwise, it will have one of the special values
ROBOT, WALL or NONE.

The pointer pnrows is used to return the
total number of rows in the environment.

The array ncols[] is used to return the
number of columns in each row.

The pointer pdirection is used to return the
direction the robot is facing (NORTH, SOUTH, EAST or WEST)

@param pnrows number of rows (returned implicitly)
@param ncols[] number of columns for each row
@param object[][] object at each location
@param pdirection which way the robot is facing (returned implicitly)
*/
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 { ...

// ... INSERT MORE CODE HERE ...

// }

}

*pnrows = r;
}

/**
Print the current state of the environment to standard output.

@param nrows number of rows in the environment
@param ncols[] number of columns in each row
@param object[][] object at each location
@param direction which way the robot is facing
*/
void print_state(
int nrows,
int ncols[MAX_ROWS],
int object[MAX_ROWS][MAX_COLS],
int direction
)
{
// ... INSERT CODE HERE ...
}
Sep 26 '06 #1
1 1911
D_C
293 100+
A switch statement may be convenient for the instructions.
Expand|Select|Wrap|Line Numbers
  1. switch(ch)
  2. {
  3.   case 'L': up += right;
  4.             right -= up;
  5.             up += right
  6.             break;
  7.   case 'R': up -= right;
  8.              right += up;
  9.              up -= right;
  10.             break;
  11.   case 'F': if(not blocked)
  12.             {
  13.                x_pos += up;
  14.                y_pos += right;
  15.             }
  16.             break;
  17.   case 'P': // call print environment
  18.             break;
  19. }
Sep 27 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Zeeshan | last post by:
Hi Everybody, I want to search the filename recursively for "this is the code original" using linux command grep or ls or any other Result should be as follows: FilenamePath and Linenumber in...
0
by: Kamliesh Nadar | last post by:
Hi I am developing a software using VB.NET I am facing following problems - 1. Though I have placed the NotifyIcon control on the window service application, after starting the service I am...
1
by: Dhiraj | last post by:
hello, everybody, this is Dhiraj here. I need help urgently, as i am getting error on my web page. The error is "Microsoft JET Database Engine error '80004005'" whenever i want to open links of...
1
by: net4matrimonials | last post by:
I m using session veriables of asp.net on two websites www.net4professionals.com(job site) and www.net4matrimonials.com (bride/groom service) when i create a session on page A i use codeing...
0
by: Asim Khan | last post by:
Dear all, A well reputable group of companies in Pakistan we urgently required a System Support Engineer for our sister concern factory located in Karachi at Korangi Industrial Area, Preference...
1
by: surrayya | last post by:
AOA: Is there any one to help me.i am in great trouble.i want to read a file in c++ program that is consisting of data in 2cols and 70 rows. Tokens freq abcd 50 dssd ...
4
by: Flamingo | last post by:
Hi folks, I want a webpage, there would be a input textfield, and a "sumbit" button there, if you press the submit button, the contents you input to the textfield would be send to your...
0
by: efix | last post by:
hey there i need help urgently.. neone hu cud help me?? U c i m tryin t figure out how to program a vb .exe to login into a internet account inreal time. i m playin an online game....
2
by: rkarthik | last post by:
Hello vectors, I am a beginner in vb.net programming and a student. As my final year project I wish to develop a compression tool.Is there any way to impleiment Huffman's compression algorithm in...
16
by: techystud | last post by:
Hi, I am doing a Left Join between two views wherein the column used in the ON condition has empty string rows in the first view. while running the query the application flashes, shows #ERROR...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.