View Single Post
Old Nov 30th, 2006, 10:54 PM   #29
aznballerlee
Hobbyist Programmer
 
Join Date: Nov 2006
Posts: 111
Rep Power: 2 aznballerlee is on a distinguished road
Quote:
Write down a list of steps, in English, of how the energySourceAt method could check whether there is an energy source at a particular location. Dont even worry about where the list is, just pretend you have a pile of pieces of paper with an energy location on each one, how would you go about finding whether a given location had an energy source.
1. Check location of robot.
2. At wherever location, check the 'piece of paper'.
3. If that 'piece of paper' has an energy source, succeed.
4. Otherwise, fail.

Quote:
For one line, responding to "look through the array" you have a lot of problems:
- I'm not even sure where you were thinking of putting that code. If it is inside the energySourceAt method, then it will be infinitely recursive. If you were going to put it in the Robot step method, then Robot doesn't have an m_sources or and energySourceAt function.
- m_sources[MAXSOURCES] is outside the boundaries of m_sources, which may cause a crash.
- You shouldn't be doing an assignment inside an if test expression
- energySourceAt returns a boolean, you can't compare that with a pointer to an energySource.
- To look through an array you need a loop.
This is inside the Valley. Anyways, still stuck on what to do. I started a loop ..
for (int k = 0; k < MAXSOURCES; k++_
{
   if ( array element has energy source  )
//  return true;
   else
     return false;
}

Earlier, you said this:
Quote:
You also need to write the energySourceAt accessor. The Valley class has an array of energy sources - you need to look through that array to see if there is one at the current coordinates.
but you're saying I can't use m_sources[m_nsources]. Confused.

Last edited by aznballerlee; Nov 30th, 2006 at 11:05 PM.
aznballerlee is offline   Reply With Quote