Objectives

The main purpose of this project is to give you an opportunity to use your linked list within the context of an agent-based simulation.

In this week's simulation, we will have Agents that are on a 2D landscape. They will have positions in a continuous (floating point) 2D space, rather than the grid from the Game of Life. Like in the Game of Life, the agents are active and will implement an updateState method.

This week, we will be discarding the need for a scale parameter. Consider your units to be pixels, so, if your Landscape's size is 500 by 500, then the Agents' positions should be between 0 and 500. You also will want to update the LandscapeDisplay class to remove all uses of the scale.

Here is a GIF example of a working simulation in action:

Tasks

Agent

Create an Agent class (it is up to you whether or not you want to make it abstract, but the instructions are written as if it is not). We will be making two forms of agents (agents with different updateState() methods). This means we will be using inheritance and need to begin with a base class - the Agent class. It needs fields to store the x and y positions (the type is double) and should implement the following methods:

Also, remember to import java.awt.Graphics so the compiler knows about the Graphics type.

Write a simple main method to test your class and its methods. Compile and run it. Make sure it works perfectly.

Grouper

Create a Grouper class. The first agent we will implement will ultimately move towards other agents, creating groups of agents. We will name the class Grouper and it will extend the Agent class.

public class Grouper extends Agent

The new class does not need any additional fields, but will need to override the constructor, updateState, and draw methods. We will save updateState for a later task. For now, implement these methods:

Write a simple test method. Compile and test your class so far (excluding draw). Get it working perfectly.

Landscape

Create a class called Landscape. It serves the same purpose as the Landscape in the Game of Life simulation, but is different enough that you probably don't want to copy the old one and edit it. Start afresh. The Landscape will need fields to store its width and height (as ints) and a LinkedList of Agents. (Note that you need your implementation of a linked list ). It needs the following methods:

Write a simple test method, compile, run, and debug.

Visualization

Make it possible to visualize your Landscape. Copy LandscapeDisplay.java from two weeks ago.

Test your visualization by running LandscapeDisplay as your main program. You will need to update the main program to create new Groupers and add them to a Landscape.

updateState( )

Add a method to your Grouper class, public void updateState(Landscape scape). It should implement the following rules.

If the cell has more than 3 neighbors within a radius of 3, then 
    the cell should move in a range of +/- 5 with a 1% chance
else
    the cell should move in a range of +/- 5

Note that the Cell's motion should be a continuous value between +5 and -5 in both X and Y. You can use the Random class's nextFloat or nextDouble method to get a random floating point value between 0 and 1.0.

updateAgents( )

Add a method to your Landscape class, public void updateAgents(), which updates the state of each agent, in a random order.

GrouperSimulation

Create a GrouperSimulation class. It should be modeled after the LifeSimulation class. It would be best to control the Landscape size and the number of agents from the command line, but it is acceptable to hard-code them. Generate and randomly place N agents (and N of 200 is reasonable) on in the Landscape. Then loop over the time steps, calling updateAgents, repaint, and Thread.sleep as in LifeSimulation. Use saveDisplay to generate the images for an animated gif, once you have it working.

CategorizedGrouper

Create a CategorizedGrouper class that extends the Grouper class. This is our second agent (since CategorizedGrouper is a Grouper and Grouper is an Agent, CategorizedGrouper is also an agent).

public class CategorizedGrouper extends Grouper

The new class should have an integer field category and implement or override the following methods.

CategorizedGrouperSimulation

Create a CategorizedGrouperSimulation class. Model this class after GrouperSimulation, using CategorizedGroupers instead of Groupers. Test it using 2 categories.

Extensions

  1. Instead of making separate main classes for each type of simulation, write just one Simulation class and make it possible for the user to control the type of Groupers from the command line.
  2. See if you can mix and match different agent types and write about what happens.
  3. Try out additional Grouper subclasses with different update rules.
  4. Experiment with the effects of modifying some of the update rules. These should be compare and contrast. Try to avoid comparing simulations where more than one thing has been changed.
  5. For any assignment, a good extension will be to implement a Java class that you have't implemented in the past projects and demonstrate that it has the same functionality as the Java class.

Writeup

Your writeup should have a simple format.

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.

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

cs231f17project4

You can give any wiki page a label using the label field at the bottom of the page. The label is different from the title.

Do not put code on your writeup page or anywhere it can be publicly accessed. To hand in code, put it in your folder on the Courses fileserver. Create a directory for each project inside the private folder inside your username folder.


When you are done with the lab exercises, you may start on the rest of the project.


© 2017 Caitrin Eaton.