CS 121: Programming Artificial Life Homework # 3. Sensing the
Neighborhood.
Due on Tuesday, April 11th, right before class.
This homework deals with sensing of the environment, as well as
detecting agent collisions. This homework build on the previous one.
Now plants and animals start with a certain energy level (how much
energy is up to you). When an animal collides with a plant, the energy
of the plant decreases, and the energy of the plant increases by the
same amount. If the energy level of a plant becomes equal or less than
zero, the plant disappears.
Animals have three ways of moving: randomly, towards the closest animal, and towards a plant. They start moving randomly.
Animals continue storing the location of their last collision with
plants. But now, after colliding with the plant, instead of
continuing to move randomly, they move towards the closest animal. Hint:
to do this, store the closest animal as an attribute, and recompute a
vector towards it continuously. You can do that by setting its
velocity to (the-location-of-the-other-animal - my-location). Because
the animal keeps moving you need to continue recomputing that vector,
or the animal will be moving towards a place that is probably empty.
When animal A collides with animal B, how A continues to move depends
on what B was doing. If B was moving towards A, then A gets information
about where B saw a plant last, and starts going towards that place. If
B was moving randomly, or B was moving towards a plant, A starts moving randomly.
At each iteration cycle, the energy of animals decreases by a certain
amount. if the energy of an animal becomes equal or less than zero, it
disappears.
At each iteration cycle, the energy of plants increases.