Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Dec 1st, 2006, 12:10 AM   #41
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 816
Rep Power: 4 The Dark is on a distinguished road
Yep, that looks right, aside from indenting and extra brackets (which are personal preference), its exactly how I would have done it.
The Dark is offline   Reply With Quote
Old Dec 1st, 2006, 12:11 AM   #42
aznballerlee
Hobbyist Programmer
 
Join Date: Nov 2006
Posts: 111
Rep Power: 2 aznballerlee is on a distinguished road
Oops, m_sources, m_nsources are indeclared.
Also this error: left of '->col' must point to class/struct/union/generic type



-'m_nsources' : undeclared identifier
-'m_sources' : undeclared identifier
-error C2227: left of '->col' must point to class/struct/union/generic type
-left of '->row' must point to class/struct/union/generic type
- 'energySourceAt' : modifiers not allowed on nonmember functions
aznballerlee is offline   Reply With Quote
Old Dec 1st, 2006, 12:28 AM   #43
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 816
Rep Power: 4 The Dark is on a distinguished road
Change
bool energySourceAt(int r, int c) const
to
bool Valley::energySourceAt(int r, int c) const
The Dark is offline   Reply With Quote
Old Dec 1st, 2006, 12:40 AM   #44
aznballerlee
Hobbyist Programmer
 
Join Date: Nov 2006
Posts: 111
Rep Power: 2 aznballerlee is on a distinguished road
Alright, I get the change. My next step is not working, I try to build on an idea, now that I have energySourceAt working.

The following fills the grid with dots, and my TODO is to place * at every energy source. Why don't this work?

	// fill the grid with dots
	for (r = 0; r < NROWS; r++)
		for (c = 0; c < NCOLS; c++)
		{
			grid[r][c] = '.';
			if (energySouceAt(r,c))
				grid[r][c] = '*';
		}

The red is an error. I'm saying ' if there's an energy source at (r,c)', then replace that dot with a *.
aznballerlee is offline   Reply With Quote
Old Dec 1st, 2006, 12:43 AM   #45
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 816
Rep Power: 4 The Dark is on a distinguished road
Quote:
Originally Posted by aznballerlee View Post
Alright, I get the change. My next step is not working, I try to build on an idea, now that I have energySourceAt working.

The following fills the grid with dots, and my TODO is to place * at every energy source. Why don't this work?

	// fill the grid with dots
	for (r = 0; r < NROWS; r++)
		for (c = 0; c < NCOLS; c++)
		{
			grid[r][c] = '.';
			if (energySouceAt(r,c))
				grid[r][c] = '*';
		}

The red is an error. I'm saying ' if there's an energy source at (r,c)', then replace that dot with a *.
Assuming this is in the Valley::display() function, you just need to put an r in
energySourceAt.
The Dark is offline   Reply With Quote
Old Dec 1st, 2006, 12:49 AM   #46
aznballerlee
Hobbyist Programmer
 
Join Date: Nov 2006
Posts: 111
Rep Power: 2 aznballerlee is on a distinguished road
Oops But this doesn't compile well either:
//    If as a result of the attempt to move, the robot is at an energy
//       source, it's recharged to the FULL_ENERGY level.

	if (energySourceAt(m_row, m_col))
		m_energy = FULL_ENERGY;
error C3861: 'energySourceAt': identifier not found

This is under the Robot:step()
aznballerlee is offline   Reply With Quote
Old Dec 1st, 2006, 12:52 AM   #47
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 816
Rep Power: 4 The Dark is on a distinguished road
The energySourceAt method is a method of Valley, so you must call it either from within another Valley method or using -> or . with a valley object.
The robot has a pointer to the Valley it is in in the m_valley member variable.
The Dark is offline   Reply With Quote
Old Dec 1st, 2006, 1:00 AM   #48
aznballerlee
Hobbyist Programmer
 
Join Date: Nov 2006
Posts: 111
Rep Power: 2 aznballerlee is on a distinguished road
Quote:
The energySourceAt method is a method of Valley
Understood.

Quote:
so you must call it either from within another Valley method or using -> or . with a valley object.
Not this part. I don't know whcih valley object to -> to the energySourceAt.
aznballerlee is offline   Reply With Quote
Old Dec 1st, 2006, 1:01 AM   #49
aznballerlee
Hobbyist Programmer
 
Join Date: Nov 2006
Posts: 111
Rep Power: 2 aznballerlee is on a distinguished road
Never mind, how about this:
m_valley -> energySourceAt(m_row, m_col)
:banana:
aznballerlee is offline   Reply With Quote
Old Dec 1st, 2006, 3:13 PM   #50
aznballerlee
Hobbyist Programmer
 
Join Date: Nov 2006
Posts: 111
Rep Power: 2 aznballerlee is on a distinguished road
Yeah, that compiles so great!
Just wondering if ..

    Robot* otherRobotAt(Robot* rp) const
//      If there is at least one robot (other than the one rp points to)
//      at the same (r,c) coordinates as the one rp points to, return a
//      pointer to the one of those other robots with the least amount
//      of energy remaining (if there's a tie, any one of the tied robots
//      will do); otherwise, return NULL.
//
	{

	}

would follow the same idea as

bool Valley::energySourceAt(int r, int c) const
{
  for (int k = 0; k < m_nsources; k++)
  {
      if ((m_sources[k]->row()== r) 
       && (m_sources[k]->col()== c))
            return true;
  }
  return false;
}
where we have to check each robot now, at each row and column to see if they match. It true, return .. a this?
aznballerlee 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 2:29 PM.

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