View Single Post
Old Nov 30th, 2006, 7:41 PM   #22
aznballerlee
Hobbyist Programmer
 
Join Date: Nov 2006
Posts: 111
Rep Power: 2 aznballerlee is on a distinguished road
Okay, thanks for clarifying this. I'm on the right track. Just a few more tasks I believe.

Next task I tried to do, but can't think of how, is the step function. I think knowing this would help me think of ideas for other functions:

I'm on bool Robot::step().
bool Robot::step()
{
	// If the robot has no energy left, return false
	// if (FULL_ENERGY == 0)
	//	return false;
	
       // Otherwise,
	else
	{	
		//    Randomly change direction with probability 1/3
		if (rand() % 3 == 0)    // 1/3 probability to pick a direction
			m_dir = Dir(rand() % 4);    // pick a random direction
		
	        //    Attempt to move one step in the direction we're currently facing.
		//      (E.g., to move north, decrement the row coordinate.)  If we can't
		//      move in that direction, don't move.
               if (r < 0  ||  r >= NROWS  ||  c < 0  ||  c >= NCOLS)
	    {
		cout << "***** Robot created with invalid coordinates (" << r << ","
			<< c << ")!" << endl;
		exit(1);
	    }
		switch (m_dir)
		{
		case NORTH:
			// TODO: Move one step north, if possible.
                        r--;
			break;
		case SOUTH:
                        r++;
		case WEST:
                        c++;
		case EAST:
                        c--;

The stuff I did was in blue. Can you tell me if I'm on the right track?
EDIT: Compiling said that r and c are undeclared! What must I do to use them?

Last edited by aznballerlee; Nov 30th, 2006 at 8:14 PM. Reason: indenting
aznballerlee is offline   Reply With Quote