Page 97 - Introduction to AI Robotics
P. 97

80
                                                                  3 Biological Foundations of the Reactive Paradigm
                                        if (hungry== NOT_PRESENT && parent==PRESENT)
                                            nurse(); // set nursed = PRESENT when done
                                        if (nursed ==PRESENT)
                                            sleep();
                                     }


                                       The example also reinforces the nature of behaviors. If the agent sleeps
                                     and wakes up, but isn’t hungry, what will it do? According to the releasers
                                     created above, the agent will just sit there until it gets hungry.
                                       In the previous example, the agent’s behaviors allowed it to feed and en-
                                     able the survival of its young, but the set of behaviors did not include fleeing
                                     or fighting predators. Fleeing from predators could be added to the program
                                     as follows:

                                       enum             Releaser={PRESENT, NOT_PRESENT};
                                       Releaser         food, hungry, nursed, predator;
                                       while (TRUE) {
                                          predator = sensePredator();
                                          if (predator==PRESENT)
                                              flee();
                                          food = senseFood();
                                          hungry = checkStateHunger();
                                          parent = checkStateParent();
                                          if (hungry==PRESENT)
                                              searchForFood();
                                          if (hungry==PRESENT && food==PRESENT)
                                              feed();
                                          if (hungry== NOT_PRESENT && parent==PRESENT)
                                              nurse();
                                          if (nursed ==PRESENT)
                                              sleep();
                                       }

                                       Notice that this arrangement allowed the agent to flee the predator re-
                                     gardless of where it was in the sequence of feeding, nursing, and sleeping
                                     because predator is checked for first. But fleeing is temporary, because it did
                                     not change the agent’s internal state (except possibly to make it more hungry
                                     which will show up on the next iteration). The code may cause the agent to
                                     flee for one second, then feed for one second.
                                       One way around this is to inhibit, or turn off, any other behavior until
                                     fleeing is completed. This could be done with an if-else statement:
   92   93   94   95   96   97   98   99   100   101   102