View Single Post
Old Dec 2nd, 2006, 4:33 PM   #60
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 824
Rep Power: 4 The Dark is on a distinguished road
I don't understand. Are you saying that we're testing the same robotToReturn each time? Does this mean I need to test the i'th element of the robotToReturn?
Trace through it in your head, or on paper. Check what value robotToReturn would have the first time round the loop. And yes, that is what you need to do.

1.
if ((otherRobotAt(Robot* rp)-> energy() == 0)
This won't compile - what is the bit in red for? Are you trying to do this without access to a compiler? If so, you are making it very hard for yourself.
It is also checking for the energy returned from the robot that otherRobotAt returns before seeing if there is a robot returned at all!
m_energy -= SHARE_AMOUNT;
otherRobotAt(Robot* rp)-> energy() = SHARE_AMOUNT;
m_energy is a member of Robot, but I think this code is in a Valley method, so you can't access m_energy directly.
You can't assign a value to an integer return value, you are probably going to have to add another Robot mutator. Maybe something like shareEnergy(Robot *with).
2. r and c may be defined in your function, but when that code is executed they don't have valid values. Even if they did you are putting the first letter of each robot on the same location over and over . The robot has a location, use it!
3. This looks right
4. You need to have a variable that indicates whether any robot made a step. Change the variable appropriately in the loop then return an appropriate value at the end.
The Dark is offline   Reply With Quote