Due date Nov. 22, 2004.
In this assignment you will build a simulation program to study the evolution
of some ecological system. An ecological system includes a number of different
organisms that have specific life-cycles and interact with others as predators
or prey. The simulation consists in creating an initial distribution of these
organisms, including their food supply, and studying how the population evolves
over time. The assignment is open-ended: feel free to experiment and complete
as much of it as possible. Your documentation should include a description of
each class and its relationship to other classes in the system (no need for UML diagrams).
For this assignment we will consider a single type of organism, some marine
invertebrate (let's call it a blob) that feeds on plankton. The blob reproduces
every so often, and the new blob is initially next to its parent (immediately
to the left). Blobs move at random in one of eight possible directions, every
second. After a number of reproductive cycles (around 10) a blob dies. A blob
feeds on the plankton at its current location. The plankton at a given location
replenishes itself in 5 seconds, so that if a blob appears at the same place
before 5 seconds there is nothing for it to eat there. Two blobs cannot be in
the same place at the same time, If a blob tries to move into an occupied space
it tries to move in the opposite direction. If this also fails it stays put
for this cycle. If a blob does not find food for 100 seconds it dies.
To program this with threads, you need one thread to describe each living
organism. Define the class Blob appropriately. Its run method is a loop that
executes a number of moves and reproductive cycles. It terminates with old age or
starvation, as described above. The state of the blob indicates how long ago
it fed, how many times it has reproduced, and where it currently is. To make
each blob behave independently, even though all of them have the same run
method, use random number generators to determine where to move, when to
reproduce, and how long to live.
A separate thread is needed to simulate the evolution of plankton. A thread
scans the space of the simulation (which will be a rectangular grid) . To
simplify things and not have to deal with actual times, we can simulate the
regrowth of the plankton by scanning all the cells sequentially with pauses
between cells, so that the whole scan takes 5 seconds, and marking each cell
that is empty of plankton and unoccupied as full again.
The simulation takes place within a frame, and each blob updates
the image by redrawing itself at a new position whenever it moves. A blob is
represented by a colored circle, and a dead blob has a different color.
Feel free to experiment with the parameters of the simulation, to find out
those that produce a more interesting effect!