appletbots
Class Agent

java.lang.Object
  extended by appletbots.WorldObject
      extended by appletbots.Agent
Direct Known Subclasses:
CarrierAgent, FriendlyAgent, Kicker, RandomAgent, SpreadOutAgent, SwarmAgent, TagAgent

public abstract class Agent
extends WorldObject

This class represents an Agent in a appletbots world.

Author:
Erik Rasmussen

Field Summary
protected  java.awt.Color accelerationVectorColor
          The color to paint the acceleration vector
protected  double maxAcceleration
          The maximum amount of acceleration for this agent
protected  int sight
          The distance the agent can see
protected  java.awt.Color velocityVectorColor
          The color to paint the velocity vector
protected  World world
          The world in which the agent exists
 
Fields inherited from class appletbots.WorldObject
color, mass, maxSpeed, size
 
Constructor Summary
Agent()
          Constructs a new agent with the following default values:
size = 5
sight = 60
maxSpeed = 5.0
maxAcceleration = 3.0
Agent(int size, int sight, double maxSpeed, double maxAcceleration)
          Constructs an agent with the given parameters
 
Method Summary
 Vector getAcceleration()
          Returns the agent's acceleration.
 double getMaxAcceleration()
          Returns the agent's maximum acceleration
 Vector getRandomAcceleration()
          Returns a random acceleration vector
 boolean getShowAcceleration()
          Returns whether or not the agent's acceleration vector will be drawn
 boolean getShowVelocity()
          Returns whether or not the agent's velocity vector will be drawn
 int getSight()
          Returns the distance this agent can see
 VectorToDraw[] getVectorsToDraw()
          Returns an array of vectors that should be drawn at the time this agent is painted
abstract  void observeWorld()
          The method invoked to allow the agent to observe the world and optionally modify his acceleration to try to achieve a goal.
protected  void setAcceleration(Vector acceleration)
          Sets the agent's acceleration vector.
 void setShowAcceleration(boolean showAcceleration)
          Sets a flag to let the agent know whether or not to draw his acceleration vector
 void setShowVelocity(boolean showVelocity)
          Sets a flag to let the agent know whether or not to draw his velocity vector
 void setWorld(World world)
          Tells the agent what world he is in.
 
Methods inherited from class appletbots.WorldObject
collidedWith, getColor, getMass, getMaxSpeed, getSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sight

protected int sight
The distance the agent can see


maxAcceleration

protected double maxAcceleration
The maximum amount of acceleration for this agent


world

protected World world
The world in which the agent exists


velocityVectorColor

protected java.awt.Color velocityVectorColor
The color to paint the velocity vector


accelerationVectorColor

protected java.awt.Color accelerationVectorColor
The color to paint the acceleration vector

Constructor Detail

Agent

public Agent()
Constructs a new agent with the following default values:
size = 5
sight = 60
maxSpeed = 5.0
maxAcceleration = 3.0


Agent

public Agent(int size,
             int sight,
             double maxSpeed,
             double maxAcceleration)
Constructs an agent with the given parameters

Parameters:
size - The agent's radius
sight - The distance the agent can see
maxSpeed - The maximum speed the agent can travel
maxAcceleration - The maximum acceleration for this agent
Method Detail

getSight

public int getSight()
Returns the distance this agent can see

Returns:
The distance this agent can see

setWorld

public void setWorld(World world)
Tells the agent what world he is in. This is called by World.addAgent().

Parameters:
world - The world the agent exists in

getRandomAcceleration

public final Vector getRandomAcceleration()
Returns a random acceleration vector

Returns:
A random acceleration vector

getAcceleration

public Vector getAcceleration()
Returns the agent's acceleration. Note that the vector returned is a clone of the internal object, so changing the returned vector will not affect the agent's acceleration. To modify the agent's acceleration, use setAcceleration(Vector).

Returns:
The agent's acceleration

setAcceleration

protected void setAcceleration(Vector acceleration)
Sets the agent's acceleration vector. If the given vector has a magnitude greater than the agent's maxAcceleration, then the vector is scaled down to the maxAcceleration.

Parameters:
acceleration - The agent's acceleration

getMaxAcceleration

public double getMaxAcceleration()
Returns the agent's maximum acceleration

Returns:
The agent's maximum acceleration

getVectorsToDraw

public VectorToDraw[] getVectorsToDraw()
Returns an array of vectors that should be drawn at the time this agent is painted

Returns:
An array of vectors that should be drawn at the time this agent is painted

setShowAcceleration

public void setShowAcceleration(boolean showAcceleration)
Sets a flag to let the agent know whether or not to draw his acceleration vector

Parameters:
showAcceleration - Whether or not to draw the acceleration vector

getShowAcceleration

public boolean getShowAcceleration()
Returns whether or not the agent's acceleration vector will be drawn

Returns:
Whether or not the agent's acceleration vector will be drawn

setShowVelocity

public void setShowVelocity(boolean showVelocity)
Sets a flag to let the agent know whether or not to draw his velocity vector

Parameters:
showVelocity - Whether or not to draw the velocity vector

getShowVelocity

public boolean getShowVelocity()
Returns whether or not the agent's velocity vector will be drawn

Returns:
Whether or not the agent's velocity vector will be drawn

observeWorld

public abstract void observeWorld()
The method invoked to allow the agent to observe the world and optionally modify his acceleration to try to achieve a goal.