//Excerpt from visionary.C. void visionary::decide(int *dx, int *dy) const { static const unsigned radius = 3; //of vision //Move one step away from a wabbit that could eat me. for (const_iterator it = begin(); it != end(); ++it) { const wabbit *const other = *it; if (other != static_cast(this) && dist(this, other) <= radius && other->hungry() > this->bitter()) { step(other, this, dx, dy); return; } } /* Arrive here if there were no enemies within the visual radius. Now see if there's any food I could eat within the visual radius. If so, take one step towards it. */ for (const_iterator it = do almost the same loop, ending with a step in the opposite direction: step(this, other, ... } //Arrive here if there were neither enemies nor food nearby: //lethargic (or random, if you wish) in the absence of stimulation. *dx = *dy = 0; }