Now let's look at behaviour in a more complex world. In the How to
run Eden handout, you demonstrated
psbug2, whose world contained
a coin and slot-machine as well as food. Here is its brain:
resolve [p,s,r]. stm . holding(+) => exec([use]). over(+) => exec([grab]). can_see(+) => move_towards(+). can_see('1') => move_towards('1'). over('1') => exec([grab]). can_see('S'), holding('1') => move_towards('S'). next_to('S'), holding('1') => turn_towards('S'). facing('S'), holding('1') => exec([use]).
Figure The source of psbug2.
The top three rules are the same as those of
psbug1, and deal
with the case where there is food to be seen. But what if there isn't?
In this world, it makes sense, if you can see a slot machine and you
have a coin, to head towards the machine and use the coin. If you don't
have a coin, it's sensible to try acquiring one. The find-and-grab-coin
behaviour is controlled by the fourth and fifth rules: I've put a blank
line before them to make them easier to see as a separate group.
The find-and-use-slot-machine behaviour is controlled by the final three rules. Notice that, unlike the others, these each have two perceptual conditions on the left-hand side, combined by a comma, the symbol for ``and''. So the first rule means
There is an added complication here. You can only use a coin in a
machine if you are facing towards it. Although in most cases, moving
towards the machine will leave the bug facing the right way, this isn't
necessarily so, e.g. if he backs towards it. Hence I have had to add a
rule to make him do so, the one which activates
turn_towards('S'). Note that I have also introduced two new
perceptual conditions. These are
next_to, which is true if the
bug is standing on an adjacent square to an object; and
which is true if he is next to an object and facing towards it.
This concludes the handout. The next thing to learn is how to use the editor to create your own rules. I shall go into this in a future handout.