View Single Post
Old Dec 1st, 2006, 6:22 PM   #53
aznballerlee
Hobbyist Programmer
 
Join Date: Nov 2006
Posts: 111
Rep Power: 2 aznballerlee is on a distinguished road
Possibly wrong, but I tried.

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.
//
{
	for (int i = 0; i< m_nrobots; i++)   // check each robot
	{
		if ((m_robots[i] -> row()==m_row)      // if robot matches coordinate
			&& (m_robots[i] -> col()==m_col && (m_robot[i]!= rp))  // and robot not the one we're looking at
			int n = m_source[i];       
			for (int j = 0; j < i; j++)        // find robot of minimum energy
			{   
				if (m_source[j] < n) 
				       n = m_source[j];
			}	
			return m_robots[i];                 //returns robot of least energy
				
	}
	return NULL;
}
aznballerlee is offline   Reply With Quote