Page 98 - Introduction to AI Robotics
P. 98
3.3 Coordination and Control of Behaviors
while (TRUE) { 81
predator = sensePredator();
if (predator==PRESENT)
flee();
else {
food = senseFood();
hungry = checkStateHunger();
...
}
}
The addition of the if-else prevents other, less important behaviors
from executing. It doesn’t solve the problem with the predator releaser dis-
appearing as the agents runs away. If the agent turns and the predator
is out of view (say, behind the agent), the value of predator will go to
NOT_PRESENT in the next update. The agent will go back to foraging, feed-
ing, nursing, or sleeping. Fleeing should be a fixed-pattern action behavior
which persists for some period of time, T. The fixed-pattern action effect can
be accomplished with:
#define T LONG_TIME
while (TRUE) {
predator = sensePredator();
if (predator==PRESENT)
for(time = T; time > 0; time--)
flee();
else {
food = senseFood();
...
}
}
The C code examples were implemented as an implicit sequence, where
the order of execution depended on the value of the releasers. An imple-
mentation of the same behaviors with an explicit sequence would be:
Releaser food, hungry, nursed, predator;
while (TRUE) {
predator = sensePredator();
if (predator==PRESENT)