Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 3rd, 2006, 1:47 AM   #71
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 810
Rep Power: 4 The Dark is on a distinguished road
You also need to fix up your Valley:~Valley destructor to loop through the m_robots and m_sources arrays and delete them individually. Do not try to delete the arrays.
The Dark is offline   Reply With Quote
Old Dec 3rd, 2006, 1:49 AM   #72
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 810
Rep Power: 4 The Dark is on a distinguished road
In this code:
    //    If at this spot there's another robot whose energy level is 0,
    //       then if we have at least SHARE_THRESHHOLD units of energy,
    //       transfer SHARE_AMOUNT units to that other robot.  (If there
    //       are two or more dead robots here, we donate to only one.)
    //    Return true, indicating the robot attempted to move.

    Robot* otherRobot = m_valley->otherRobotAt(this);

    if (otherRobot != NULL)
    {
        if ((m_energy > SHARE_THRESHHOLD))
        {
            m_energy -= SHARE_AMOUNT;
            otherRobot-> m_energy = SHARE_AMOUNT;
            return true;
        }
    }
Where is the check for the energy level being zero?
The Dark is offline   Reply With Quote
Old Dec 3rd, 2006, 10:36 AM   #73
aznballerlee
Hobbyist Programmer
 
Join Date: Nov 2006
Posts: 111
Rep Power: 2 aznballerlee is on a distinguished road
1. I fixed up the switch statement, I think this would be more logical.
        //    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.
        switch (m_dir)
        {
        case NORTH:
            // TODO: Move one step north, if possible.

            if (m_row-- < 0  ||  m_row-- >= NROWS)
            {
                break;      // do nothing don't move
            }
            m_row--;       // otherwise, decrement row coordinate
            break;
            
// TODO: Implement the other movements
        case SOUTH:
            if (m_row++ < 0  ||  m_row++ >= NROWS)
            {
                break;
            }
            m_row++;
            break;

        case WEST:
            if (m_col-- < 0  ||  m_col-- >= NCOLS)
            {
                break;
            }
            m_col--;
            break;

        case EAST:
            if (m_col++ < 0  ||  m_col++ >= NCOLS)
            {
                break;
            }
            m_col++
                break;
        
        default:
            cout << " ***** Direction must be valid" << endl;
        }        
    }

2. I changed my destructor for valley too. I realizede that I hadn't deleted each element inside the array I allocated. So I fixed that.

//      TODO:  Implement the destructor
//      Delete any dynamically allocated objects held by the Valley.
Valley::~Valley()
{
    for (int f = 0; f < m_nrobots; f++)
        delete [] m_robots[f];

    for (int g = 0; g < m_nsources; g++)
        delete [] m_sources[g];
}

3. Oops, forgot that. How's this now.
	Robot* otherRobot = m_valley->otherRobotAt(this);

	if (otherRobot != NULL)
	{
		if ((otherRobot -> m_energy == 0) && (m_energy > SHARE_THRESHHOLD))
		{
			m_energy -= SHARE_AMOUNT;
			otherRobot-> m_energy = SHARE_AMOUNT;
			return true;
		}
	}
	return true;
}
aznballerlee is offline   Reply With Quote
Old Dec 3rd, 2006, 1:29 PM   #74
aznballerlee
Hobbyist Programmer
 
Join Date: Nov 2006
Posts: 111
Rep Power: 2 aznballerlee is on a distinguished road
Never mind, The Dark. I fixed all my errors. I'll PM you the code if you want me to.
aznballerlee is offline   Reply With Quote
Old Dec 3rd, 2006, 5:42 PM   #75
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 810
Rep Power: 4 The Dark is on a distinguished road
Good job. Hope it all goes well.
I hope you got rid of a few of those "--"s in 1 and the "[]"s in 2.

Its fun to watch those robots walk around.
The Dark is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Wierd compile Error. Need help please. Keiyentai Java 7 Aug 19th, 2006 1:35 AM
What is: "Oriented programming (OO)?" BrinyCode C++ 12 Nov 22nd, 2005 7:40 AM
Java programmers, game developers, artists, be ware! RPG game team is recruiting! atcomputers.us Paid Job Offers 7 Sep 25th, 2005 7:25 PM
User Input for Number Format ericelysia1 Java 0 Jul 21st, 2005 3:41 PM
Programmers Needed! Online Game troy_eisert C++ 2 Jan 29th, 2005 12:51 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:54 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC