appletbots.friendly
Class FriendlyAgent
java.lang.Object
appletbots.WorldObject
appletbots.Agent
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
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 java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
FriendlyAgent
public FriendlyAgent(int size,
int sight,
double maxSpeed,
double maxAcceleration)
- Constructs a new FriendlyAgent with the given parameters
- Parameters:
size
- The agent's radiussight
- The distance the agent can seemaxSpeed
- The maximum speed the agent can travelmaxAcceleration
- The maximum acceleration for this agent
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