You'll find code that creates a new Agent in each class's
act()
where the instance tries to reproduce. If you
compare all three species, you'll find that there are three parts that
they have in common:
enterGrid()
method); and
setAgentAt()
.
enterGrid()
, you'll
get a null pointer exception when the new agent tries to
act()
, because it won't have either a grid or a location
in one. If you leave out the call to setAgentAt()
, your
new agent will never be asked to act (and it will never be found by
any other agent).
Note also that if you want one agent to be moved by another agent (as
when, for example, a hawk might pick up a rabbit and drop it somewhere
else), you'll need to call the moved Agent's enterGrid()
to tell it where it has landed as well as telling the grid what cell
it occupies.