book cover
book cover

Programming Projects

Ecology

maintained by Francis Glassborow

  Home     

Predator-Prey Simulation

Contributed by Chris Theis

Implement the simulation of an ocean (a big matrix, implement so that opposite edges are adjacent, i.e. when you leave by one edge you re-enter at the opposite edge. Effectively that creates a toroidal ocean) that is populated by fish and sharks. Sharks feed on fish and both species can get pregnant. They move from matrix cell to another adjacent matrix cell at each time step. This movement can be random, although sharks have a higher probability to move towards a fish. Fish of course will try to move away. Adjusting both probabilities the predator & prey speed can be simulated. If a shark does not feed for a certain amount of adjustable time steps it dies. Both species can become (randomly) pregnant and spawn a child after and adjustable amount of time steps. Adjusting these parameters one can (especially if it is shown graphically) observe a common predator & prey population as can be seen in nature.

Program elements

Extensive use of standard vectors of vectors is enforced in this example.


  Home      Ecology      You Can Do It!