appletbots.friendly
Class FriendlyAgent

java.lang.Object
  extended by appletbots.WorldObject
      extended by appletbots.Agent
          extended by appletbots.friendly.FriendlyAgent

public class FriendlyAgent
extends Agent

A friendly agent looks at all the other agents he can see and randomly selects one to be his friend. However, he can only make another agent his friend if the other agent does not already have the agent selected as his friend. The friendly agent then tries to move toward his friend by accelerating towards him. The agent remembers who his friend is and continues to accelerate towards him as long as the friend remains visible. If the agent ever loses sight of his friend he simply selects another one at random given the selection criteria stated above. If ever a friend cannot be found the agent accelerates in a random direction to search for one.

Author:
Erik Rasmussen

Field Summary
 
Fields inherited from class appletbots.Agent
accelerationVectorColor, maxAcceleration, sight, velocityVectorColor, world
 
Fields inherited from class appletbots.WorldObject
color, mass, maxSpeed, size
 
Constructor Summary
FriendlyAgent(int size, int sight, double maxSpeed, double maxAcceleration)
          Constructs a new FriendlyAgent with the given parameters
 
Method Summary
 Agent getFriend()
          Returns the selected friend
 void observeWorld()
          Observes the world, and follows the Friendly Agent Algorithm.
 
Methods inherited from class appletbots.Agent
getAcceleration, getMaxAcceleration, getRandomAcceleration, getShowAcceleration, getShowVelocity, getSight, getVectorsToDraw, setAcceleration, setShowAcceleration, setShowVelocity, setWorld
 
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
 

Constructor Detail

FriendlyAgent

public FriendlyAgent(int size,
                     int sight,
                     double maxSpeed,
                     double maxAcceleration)
Constructs a new FriendlyAgent 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

observeWorld

public void observeWorld()
Observes the world, and follows the Friendly Agent Algorithm.

Specified by:
observeWorld in class Agent

getFriend

public Agent getFriend()
Returns the selected friend

Returns:
The selected friend