Project 5 (Draft)
Due Thursday 7/26/2001
Last Modified
One of the frequent uses for a computer is to model a system and one of the earlest, called "life", grew out of 1970
artical in Scientific American. In most such simulations all changes are assumed to all take place simultaniously and they usualy model one kind of organisms in isolation. For this project you will create a version of this simulation in a grid of at least 10x10 and not to exceed 100x100 with 3 types or creatures where changes do not need to take place simultaniusly.
What you will need to do
Each of the 3 creatures is described bellow.
Common Oyster Crassostrea Virginica
- Gray Squares
- If all 6 neighbors are Oysters die of overpopulation
- Any empty neighboring cell may be a birth cell
Green Fleece seaweed Codium fragile
- Green Squares
- If no neighbors of seaweed dies of isolation
- Any neighboring Oyster cell may become a birth cell --this kills the Oyster
Willcox's Sea Hare Aplysia Willcoxi
- Purple Squares
- May only 10 turns with out eating 1 square of seaweed or die, eating a square of seaweed kills the seaweed.
- If an Aplysia eats will produce a new Aplysia in an empty neighbor or one that has seaweed.
- If a square next to an Aplysia has a sea weed then the Aplysia will move into that square. If there is no sea weed then the Aplysia will move in a random dirrection.
- An Aplysia will not move into a square with an Oyster
- After 10 moves without eating an Aplysia will die.
The world these creatures live in is a torus so there is no edge.
Rather than being turned bases each creature will wait between 1 and 60 sec before trying to make another move. Between moves it may be killed off by antoher creature.
The code to sleep 1 to 60 seconds would be: 1+( 59000*(int)(Math.random()) )
Starting conditions, you may hardcode the starting conditions of your simulation. There should be between [15 - 25] creatures with each creature having at least 4 representatives.
You will need to use 2 aspects of multi-threading,
- each active creature will need to have its own thread or each square will need its own thread.
- You will need to impliment mutual exclusion so that only one thread may update the array that represents the world at a time.
The display for this is a grid layout of colour squares (1 for each in the world) that can be one of 4 colours (1 for each animal) and brown for the background.
What to submit
The code.