CS 231: Assignment #5

Designing our Simulation System

So far, the design of the simulation system has been determined for you. This week you'll start to design a system yourselves based on some specifications, interfaces, and parent classes.

Documentation for Java 1.5 is located at: Java 1.5 SE API.

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

Problem Description

You need to design a system for simulating entities on a landscape. Conceptually, the landscape should be a continuous planar surface (not a grid of boxes).

The Landscape should contain three kinds of things: Agents, Resources, and Obstacles.

Using the above four base types (parent classes or interfaces), we will write a generic Simulation class that iterates over time, updating the landscape. The Simulation should know nothing about the specific rules for Agents, Resources, or Obstacles, and should use nothing but methods defined by the appropriate interfaces or parent classes.

This week we will begin the process of defining the task using a top-down design methodology. We will start by designing the Simulation parent class, which will help us to design the interfaces and parent classes for the base data types. The goal this week is to develop a design only. Throughout the design process, keep in mind that the system should be flexible enough to implement any of the prior three scenarios.

Tasks

  1. Create a brand new Simulation class. This class will be the parent of all simulations. The simulation class has to be able to do four things.

    1. Initialize a landscape. There should be a default behavior (e.g. the game of life), but each simulation child class will overwrite this method to set up different simulations.
    2. Execute one iteration of the simulation. This function should be generic for any simulation. It should execute an update on each obstacle, an update on each resource, an update on each agent, and a post-update on each agent. We'll talk about this in lab.
    3. Display the current state of the simulation and pause for a given amount of time. The simulation should not know anything about how to do the mechanics of the update except call the appropriate method on the appropriate object.
    4. Run the simulation in a main function. You can avoid writing new main functions in your child simulation classes by have a system that selects which simulation to run based on command line arguments.

  2. Focusing on the Initialize and Iterate methods of the Simulation, plan out what methods the Landscape (class), Agent (interface), Resource (interface), and Obstacle (interface) classes or interfaces require. We'll go over this in lab. After a collective design phase, I'll link the three common interfaces here. You are welcome to add to the interfaces to implement extensions, but you cannot subtract from them.
  3. Agents, Resources, and Obstacles should know how to draw themselves. Add draw functions to your design and think about how your system should pass around the appropriate information. Each of these things, for example, needs to know where to draw itself and how big to make the drawing. Only the landscape display class knows anything about the scale of the display and the relationship of the viewing window to the Landscape coordinates. Use this LandscapeDisplay class to design your system.
  4. Your task this week is to write an initial version of the Simulation class, a skeleton Landscape class (methods and fields, but no code), and the three interfaces. You should be able to compile your simulation class, but it won't do anything yet. Your writeup will be your primary output, as it will explain your design and the functionality of the methods defined in the interfaces.

Extensions

  1. Complete a simple simulation, such as the social simulation from lab 2, using your new system. Something even simpler is to have the agents just wander randomly around the landscape.
  2. Designs that are exceptionally well presented will receive extension credit.

Handin

Make your writeup for the project a wiki page in your personal space. If you have questions about making a wiki page, stop by my office or ask in lab.

Your writeup should have a simple format.

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

cs231f09project5

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 Academics server in your folder within the COMP/CS231 directory.