Class Agent

java.lang.Object
  extended by SimpleTurtle
      extended by Turtle
          extended by Agent
Direct Known Subclasses:
BirdAgent, CrowdAgent, DEAgent, DeerAgent, DSAgent, EggAgent, NBDAgent, PersonAgent, PoliticalAgent, WolfAgent

public class Agent
extends Turtle

Class that represents a general Agent. We are designing to offer more flexibility than one might expect to use.

Author:
Mark Guzdial guzdial@cc.gatech.edu, Barb Ericson ericson@cc.gatech.edu

Field Summary
static int MAX_SPEED
          class constant for top speed (max num steps can move in a timestep)
static double PROB_OF_STAY
          class constant for probability of NOT turning
protected static Random randNumGen
          random number generator - protected allows direct access by children
 
Constructor Summary
Agent(int x, int y, ModelDisplay modelDisplayer, Simulation thisSim)
          Constructor that takes the x and y, a model display to draw it on, and the simulation
Agent(ModelDisplay modelDisplayer, Simulation thisSim)
          Constructor that takes the model display (the original position will be randomly assigned) and the simulation
 
Method Summary
 void act()
          Method to act during a time step.
 void act(int t)
          act() with a timestep
 int countInRange(double range, LinkedList list)
          Method to count the number of agents within the range that are on the given list
 void die()
          Method that handles when an Agent dies
 Agent getClosest(double distance, LinkedList list)
          Method to get the closest agent within the passed distance to this agent but NOT this agent.
 Picture getPicture()
          Method to get the picture
 Simulation getSimulation()
          Method to get the simulation
 int getSpeed()
          Method to get the speed
 void init(Simulation thisSim)
          Method to initialize the new agent object
 void setPicture(Picture pict)
          Method to set the picture
 void setSpeed(int velocity)
          Method to set the speed
 
Methods inherited from class SimpleTurtle
backward, backward, clearPath, drawInfoString, drop, forward, forward, getBodyColor, getDistance, getHeading, getHeight, getInfoColor, getModelDisplay, getName, getPen, getPenColor, getPenWidth, getShellColor, getShowInfo, getWidth, getXPos, getYPos, hide, isPenDown, isVisible, moveTo, paintComponent, penDown, penUp, setBodyColor, setColor, setHeading, setHeight, setInfoColor, setModelDisplay, setName, setPen, setPenColor, setPenDown, setPenWidth, setShellColor, setShowInfo, setVisible, setWidth, show, toString, turn, turnLeft, turnRight, turnToFace, turnToFace, updateDisplay
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROB_OF_STAY

public static final double PROB_OF_STAY
class constant for probability of NOT turning

See Also:
Constant Field Values

MAX_SPEED

public static final int MAX_SPEED
class constant for top speed (max num steps can move in a timestep)

See Also:
Constant Field Values

randNumGen

protected static Random randNumGen
random number generator - protected allows direct access by children

Constructor Detail

Agent

public Agent(ModelDisplay modelDisplayer,
             Simulation thisSim)
Constructor that takes the model display (the original position will be randomly assigned) and the simulation

Parameters:
modelDisplayer - thing that displays the model
thisSim - my simulation

Agent

public Agent(int x,
             int y,
             ModelDisplay modelDisplayer,
             Simulation thisSim)
Constructor that takes the x and y, a model display to draw it on, and the simulation

Parameters:
x - the starting x position
y - the starting y position
modelDisplayer - the thing that displays the model
thisSim - my simulation
Method Detail

getPicture

public Picture getPicture()
Method to get the picture

Overrides:
getPicture in class SimpleTurtle
Returns:
the picture for this agent

setPicture

public void setPicture(Picture pict)
Method to set the picture

Overrides:
setPicture in class SimpleTurtle
Parameters:
pict - the picture to use

setSpeed

public void setSpeed(int velocity)
Method to set the speed

Parameters:
velocity - the new speed to use

getSpeed

public int getSpeed()
Method to get the speed

Returns:
the current speed

getSimulation

public Simulation getSimulation()
Method to get the simulation

Returns:
the simulation

init

public void init(Simulation thisSim)
Method to initialize the new agent object

Parameters:
thisSim - the simulation

die

public void die()
Method that handles when an Agent dies


getClosest

public Agent getClosest(double distance,
                        LinkedList list)
Method to get the closest agent within the passed distance to this agent but NOT this agent. We'll search the input list of the kind of objects to compare to.

Parameters:
distance - the distance to look within
list - the list of agents to look at
Returns:
the closest agent in the given distance or null

countInRange

public int countInRange(double range,
                        LinkedList list)
Method to count the number of agents within the range that are on the given list

Parameters:
range - the number of steps within which to consider agents
list - of agents to consider
Returns:
the number of agents within range.

act

public void act(int t)
act() with a timestep

Parameters:
t - the timestep

act

public void act()
Method to act during a time step. The default is to pick a random direction and move some random amount up to the top speed.