UW Home     CSE Home   Announcements    Message Board    Contact Info 

 
 

Project 3

Due Wednesday, March 10, 9pm -- No late assignments will be accepted.

Overview

This program is a simple simulation of Critters interacting in a world where Critters are born, they eat, they reproduce, and they die. A world something like our own, but somewhat less complicated. Download the distribution file (cse142-proj3-R4F2.zip) and unzip it to the directory where you will be working.

There are numerous Critters that can inhabit our BugWorld. The world is initially populated with examples of all the Critters. The user can step the model manually and advance one step at a time (use the 's' key) , or the program can animate, running step after step continuously (use the 'a' key to animate faster, use the 'A' key to animate slower).

Every Critter is created with a variety of life characteristics, including life span, reproduction span, maximum calories, calorie burn rate, and maximum strength. As the Critter lives its life, other characteristics are calculated at every step, including age, current calories, and power (max strength scaled by curCalories / maxCalories).

At each step, all the creatures get older by one tick and burn their allotted number of calories. If the Critter has lived its life span or has run out of calories, it dies and its remaining calories are spread around to the inhabitants of the neighboring eight cells.

If the number of ticks in the reproduction span has passed since birth or the last reproduction event, then a new Critter is created in an empty spot near the original Critter. If none of the eight neighbor cells are empty, the Critter does not reproduce.

All the Critters are asked where they would like to go on the next step. They can look at the current occupants of various cells (generally neighbors, but not limited to that), and announce their choice (generally a neighboring or nearby cell, but not limited to that). It is not required that a Critter move at all. For example, the Grass never moves, and the Insects only move if there is a weaker Critter in a neighboring cell. After all Critters have made a selection, they are put in the cell they requested. Mayhem ensues because it's likely that several Critters will want to move to the same spot. Only the most powerful Critter in each cell survives. The calories of all the victims are given to the survivor (up to its maximum) and the process begins again.

screen shot

Class and Interface design

Gobbler - The main class of the program. Execution starts here first.

BugWorld - Constructs the model and the views. Listens for commands from the keyboard.

BugWorldModel - Implements the model and initialization thereof. Extends sim.BasicMatrixModel that does most of the work.

BugWorldView - Shows the cells in the matrix

Grass, Insect - Sample inhabitants of the MatrixModel. These classes implement the Critter interface. Objects that implement the CritterInfo interface are used to track the relevant life characteristics.

GrassFace, InsectFace - Graphic representation of associated Critter. These classes implement the CritterFace interface.

The sim package includes all the interfaces and the abstract class BasicMatrixModel. You should not change anything in the sim package, but you are welcome to read the code there.

Usage

>java Gobble

Keyboard commands:

s - Single step. Stops animation if it is running.
a - Animate. 1 second frame time initially, repeated "a" entries cut the frame time in half.
A - Animate. 1 second frame time initially, repeated "A" entries double the frame time.
q - Quit the program.

Assignment

The goal of this project code is to create and run a world in which a variety of Critters can live their lives together. Individual Critters live and die, but the populations continue. The required part of this homework is to implement two more Critters and add them to the world, as described in this section.

There are two major influences on the way a Critter behaves. First, there are several parameters that describe significant characteristics: life span, reproduction span, maximum calories, calorie burn rate, and maximum strength. You set those when you initialize a new Critter object in its constructor. Note that while the Critter exists, the maximum strength value stays the same, but the power value is calculated each step. Power is equal to maximum strength*(curCalories/maxCalories), so if the Critter is very hungry, it is also weaker. When several Critters choose the same cell to jump to, the most powerful one is selected as the survivor.

Second, each type of Critter has an algorithm for deciding where to move on the next tick of the clock. This algorithm is implemented in the selectNextCell() method of the Critter. If your selectNextCell() algorithm wants to know about its neighbors it can ask the model about a particular cell, and then use the getCritterInfo() method to find out the current state of the other Critter (if any). See the implementation of Insect for an example of how to do this.

The required portion of this assignment is as follows:

  1. Implement two more classes that implement the Critter interface. You can copy and paste from Grass or Insect to start from, but your new Critters must include a new algorithm for selecting the cell to jump to on each tick and some different values for the call to createCritterInfoInstance().
  2. Implement two new classes that implement CritterFace to go along with your new Critters.
  3. Modify the initializePopulation() method in BugWorldModel to include all four Critters. You don't need to use the loops that are there - use any method you like to select where to put the initial examples of your Critters in the world.
  4. Run your model to understand the behavior over several minutes of animation.

In general, the goal of a dynamic environment like this is to have a world in which Critters live and die but none of the populations die out completely. This is very difficult to achieve and is not required, but try to design your Critters so that they don't get completely wiped out early on.

You can modify or add new classes in the Gobble directory. Do not modify or turn in any code in the sim directory.

Extensions

This project can be extended in many ways. You are not required to do any extensions.

Some extra credit will be awarded for extensions that go beyond the basic requirements. The scale that will be used for grading the extended project is:

* something beyond the basic requirements
** something significantly beyond the basic requirements
*** truly outstanding - worth a separate trip to check out - so amazing that the TA runs down the hall to show others

The list that follows is for your consideration as a source of ideas. Feel free to come up with your own ideas too. You can modify or add new classes in the Gobble directory. Do not modify or turn in any code in the sim directory.

  • Conduct a series of experiments to understand how changing one or two life parameters or simple changes to the selectNextCell() algorithm affect the long term survival of your Critters. Document the experiment design and the results.
  • Replace Grass or Insect with new classes that have significantly different selectNextCell() algorithms.
  • Replace GrassFace or InsectFace with new CritterFace classes that have more than one graphic Shape element, perhaps depending on the requested cell size.
  • Implement a CritterFace that shows some indication of an interesting CritterInfo factoid like age or power. For example, the face might include graphic elements that change color according to certain conditions. If the face size is large enough, it might include a TextShape or two with information that gets updated on every pass through selectNextCell().
  • Implement several more Critters, each of which differ significantly in their implementation of selectNextCell() and have their own unique CritterFaces. Populate a world with examples of each Critter species, and show that all species are still around after running for several minutes.
  • Create another view in BugWorld that shows fewer cells with more space allocated to each cell. This can be done by setting the BugWorldView parameters. This results in a zoomed view of the upper left corner of the model. A zoomed view like this could be used in conjunction with faces that contain more information about the state of a Critter to provide a local view of what's happening.
  • Write a new abstract class BasicCritter that implements some of the behavior of the Critters in your world (for example a constructor that takes life, repro, maxCal, burn, and strength, and also the getCritterInfo() method) and leaves the rest as abstract methods for the subclasses to implement. Rewrite the Critters in your world to extend BasicCritter.
  • Implement command line parameters that can be passed to Gobble to set the size of the world. Remember that the keywords entered on the command line are passed to the main() method in its String[] argument.
  • Write a new view BugWorldZoomView that shows a smaller area of the world but using larger cell sizes. The upper left corner of the zoomed region, the number of cells wide and high, and the size of the display cells should be specified by BugWorld in the BugWorldZoomView constructor call.
  • Write another view that is completely different from the existing view. For example, a view could be written that kept track of how many of each kind of Critter currently exists in the model.

What to turn in

Use this online turnin form to turn in the files that make up your project. You should turn in the files that you received from us, either the originals or your modified versions, and the additional files you created. However, do not turn in any of the files in the sim folder. The original versions of those files are already on the turnin server and will be used when your program is compiled.