CS 231: Assignment #5

Predator, Prey, and Obstacles

The goal of this project is to enable you to create your own simulation that incorporates the idea of predator (consumer), prey (resources), and obstacles (places an agent can't go). Continue to use the design framework from project 4, but create a more complex set of agents in inhabiting the landscape together.

Documentation for Java 1.6 is located at: Java 1.6 SE API

Problem Description

The goal is to create a balanced simulation with three types of agents: consumers, producers, and obstacles. For example, the consumers could be broccoli fiends, the producers could be broccoli plants, and the obstacles may be fences. You can choose your own scenario (zombies and plants, hobbits and mushrooms, etc.).

At a high level, the consumers need to get broccoli from the plants or their health goes down. If a consumer's health gets too low, they die and are removed from the simulation. Producers make broccoli at a certain rate over time, but may die from overharvesting, and obstacles block consumers from moving inside them. Both the broccoli plants and the broccoli fiends should create new plants and new fiends when the conditions are right. Plants don't move much, except when they split off from their parent plant; fiends move around when they don't have much to each in their local neighborhood, and sometimes they move even then.

Continue to use the concept of a 2D Landscape with agents representing their location on the Landscape as continuous variables. A Landscape should support agents and obstacles. While you can hold both agents (Cell child classes) and obstacles (also a Cell child class) within the same list, it may be easier to separate the two so that obstacles can be accessed separately from agents.


  1. Re-implement your LinkedList class as a doubly-linked list with a head and a tail pointer and prev/next pointers at each node. It should have the same functionality as the original LinkedList.
  2. Plan out your simulation. Select a consumer, a producer, and an obstacle and plan out the rules for each. Then build a subclass of Cell for each one that implements the concept. You may want to add additional abstract methods to the Cell class to guarantee that all of the different sub-class types implement a minimum set of methods.

    You are free to create an interface for an Agent and an interface for an Obstacle as well, if you wish to use that method of defining a set of common functions.

  3. Write the individual agent classes. As you write one class, you may want to test it out to see if it is behaving correctly in the absence of other agents. For example, broccoli plants should grow in health and make new plants; broccoli fiends should start out numerous, shuffle around, and quickly die away with no broccoli to eat. Obstacles should draw their extent and just sit there.
  4. Make sure each different individual class draws itself in a unique, easily identfiable manner (get creative).
  5. Update your Landscape class code as you update the individual agent classes. You may want to have separate lists for agents and obstacles, and separate accessor methods, since you'll need to loop over the list of obstacles any time an agent moves.
  6. Add an initialization function to the Landscape that generates appropriate initial conditions. You'll need to experiment.
  7. Update the main method in LandscapeDisplay to call the Landscape initialization function and start running the simulation. Enable it to save each step of the simulation to a file so you can create an animated GIF.
  8. Run your simulation for 100 iterations. Do this several times. Include in your writeup a fairly small simulation that demonstrates the system is functional and working correctly.


  1. Do more than one set of simulation rules.
  2. Get creative with the visualizations of each agent type.
  3. Show experimentation with different rules and how these changes affect the simulation.
  4. Implement an additional data structure, such as an ArrayList.
  5. Give each Agent a unique ID and keep the linked list sorted by ID. Does this assist any of the operations?
  6. Focus on speeding up the simulation. What can you do to make it faster? Show before/after timing to demonstrate your speedups.


Make your writeup for the project a wiki page in your personal space.

Your writeup should have a simple format.

Once you have written up your assignment, give the page the label:


You can give any page a label when you're editing it using the label field at the bottom of the page.

Do not put code on your writeup page or anywhere it can be publicly accessed. To hand in code, put it on the Courses volume in your folder within the COMP/CS231 directory.