Project 3

Due Date: Fri 16 Dec (firm)

Pair Project


An understanding of
  • concurrency
  • actor model
  • agent-based simulation


In this project, we will build an agent-based model of an ecosystem of predators and their prey, based on the NetLogo tutorial referenced below. We will have the following agents and respective behaviors: 
  • Hare
    • Move randomly in the world.
    • Check to see if you should reproduce this time.
    • Check to see if you’ve reached maximum age.
  • Lynx
    • Move randomly in the world.
    • Check to see if you landed on a hare to eat.
    • Check to see if you should reproduce this time (requires enough energy to have a kitten).
    • Check to see if you’ve reached maximum age. 
    • Check to see if you’re out of energy.
The model's behavior depends on the following parameters:
  • world-width
  • world-length
  • initial-hares 
  • initial-lynx 
  • hare-birth-rate 
  • max-hare-age 
  • lynx-energy-to-reproduce 
  • energy-per-hare-eaten 
  • max-lynx-age
The model proceeds according to a shared clock (see below for more details). With each clock tick, the system reports the sizes of each population.

You are strongly encouraged to experiment with different combinations of parameter values and observe the resulting behavior of the ecosystem.


  • The parameters are set in a central configuration object.
  • Each agent is represented as a Scala actor. You are expected to follow the practices recommended in section 32.5 of the main course text, in particular:
    • using non-blocking actors (based on react loops) wherever possible
    • making messages immutable and self-contained
  • Do not use any thread-safe data structures that employ locking. Instead, wrap any shared state, such as the two populations, in a suitable actor. For example, you could introduce a World actor that includes the populations and shared clock and supports any messages the agents need to interact, such as a lynx landing on a hare.
  • Unit-test your actors using suitable instrumentation such as mock actors.

Written Part

In about 600-900 words (two to three pages), succinctly discuss your experience with this project and address how the choice of actors impacted the following dimensions of your work:
  • overall architecture
  • communication among objects
  • testing
  • readability and the ability to reason about the code
Also discuss similarities with and differences from the NetLogo solution.

Extra Credit

These two extra-credit opportunities can be combined or chosen separately. Each earns you up to 10% extra credit.
  • Simple visualization (see also chapter 34).
  • Turning the model into an interactive game by allowing the player to hunt hares and lynxes.