simuLCS
Class Agent

java.lang.Object
  extended bysimuLCS.Entity
      extended bysimuLCS.Agent
Direct Known Subclasses:
AgentClassifier, AgentDuck, AgentInteractive

public class Agent
extends Entity

A basic Agent, placed randomly inside the Arena and moving randomly (no specific behaviour). It provides basic functions such as painting the Agent, erasing it,...

Author:
Benoit

Field Summary
protected  Arena arena
          Link to the Arena where the agent is placed.
protected  double heading
          Angle which determines where the agent is heading
protected  java.awt.geom.Point2D oldcoord
          Old coordinates (of the previous position).
 
Fields inherited from class simuLCS.Entity
color_ext, color_int, coord, generator, name, paintName, size
 
Constructor Summary
Agent(java.util.Random gen, Arena a)
          Constructs an Agent placed randomly inside the Arena.
Agent(java.util.Random gen, Arena a, java.lang.String name)
          Constructs an Agent placed randomly inside the Arena with the name name.
 
Method Summary
 void clear(java.awt.Graphics2D g)
          Clear the drawing of the agent at the current coordinates.
 void clear(java.awt.Graphics2D g, java.awt.geom.Point2D c)
          Clear the drawing of the agent at the indicated coordinates (Basically, a white circle is drawn)
 Arena getArena()
          Returns a pointer to the Arena where the Agent is placed.
 ClassifierSet getBehaviour()
          For compatibility reasons, subclasses might implement an Agent whose behaviour is described by a ClassifierSet.
 ClassifierSet getBehaviour(int i)
          Get the classifier set representing the behaviour of the Agent.
 java.awt.geom.Point2D getCoordNearTo(Entity otherEntity)
          Return the closest point of the Agent to another Entity
 double getRadius()
          Get the radius of the agent (which is a circle).
 boolean isDangerous()
          By default, an Agent is not dangerous.
 boolean isMoving()
          By default, an Agent is a moving entity.
 void move()
          Move the agent randomly.
 void move(Arena a, Entity[] others, int nbagents, java.awt.Graphics2D g)
          Move the Agent by modifying its coordinates.
 void paint(java.awt.Graphics2D g)
          Remove the drawing of the agent for the old coordinates and repaint the agent at its new coordinates (This avoids a blinking effect)
 java.lang.String toString()
          Creates a String describing the Agent
 
Methods inherited from class simuLCS.Entity
collideWithMe, distanceTo, getColor_ext, getColor_int, getCoord, getId, getName, getRadiusBody, getSize, isPaintName, setColor_ext, setColor_int, setName, setPaintName, setSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

heading

protected double heading
Angle which determines where the agent is heading


arena

protected Arena arena
Link to the Arena where the agent is placed.


oldcoord

protected java.awt.geom.Point2D oldcoord
Old coordinates (of the previous position). Used to avoid the blinking effect while the Agent is moving.

See Also:
paint(Graphics2D)
Constructor Detail

Agent

public Agent(java.util.Random gen,
             Arena a)
Constructs an Agent placed randomly inside the Arena.

Parameters:
gen - The generator for the random numbers
a - the Arena where to put the agent
See Also:
Arena.isInside(double, double, double)

Agent

public Agent(java.util.Random gen,
             Arena a,
             java.lang.String name)
Constructs an Agent placed randomly inside the Arena with the name name.

Parameters:
gen -
a -
name -
Method Detail

getRadius

public double getRadius()
Get the radius of the agent (which is a circle).

Returns:
the radius (size/2)
See Also:
Entity.size

paint

public void paint(java.awt.Graphics2D g)
Remove the drawing of the agent for the old coordinates and repaint the agent at its new coordinates (This avoids a blinking effect)

Overrides:
paint in class Entity
See Also:
Entity#paint()

clear

public void clear(java.awt.Graphics2D g,
                  java.awt.geom.Point2D c)
Clear the drawing of the agent at the indicated coordinates (Basically, a white circle is drawn)

Overrides:
clear in class Entity
Parameters:
g - Graphics
c - The coordinates where to clear the drawing of the agent.

clear

public void clear(java.awt.Graphics2D g)
Clear the drawing of the agent at the current coordinates.

Parameters:
g - Graphics
See Also:
clear(Graphics2D, Point2D)

move

public void move()
Move the agent randomly. As an example, here the agent moves randomly (on the left or the right + up or down)


move

public void move(Arena a,
                 Entity[] others,
                 int nbagents,
                 java.awt.Graphics2D g)
Move the Agent by modifying its coordinates.

Specified by:
move in class Entity
Parameters:
a - The Arena inside which to move
g - Graphics
See Also:
Entity.move(Arena, Entity[], int, Graphics2D)

getArena

public Arena getArena()
Returns a pointer to the Arena where the Agent is placed.

Returns:
The arena

isDangerous

public boolean isDangerous()
By default, an Agent is not dangerous. Subclasses might be Dangerous and therfore should override this function.

Specified by:
isDangerous in class Entity
Returns:

isMoving

public boolean isMoving()
By default, an Agent is a moving entity.

Specified by:
isMoving in class Entity
Returns:
true

getBehaviour

public ClassifierSet getBehaviour()
For compatibility reasons, subclasses might implement an Agent whose behaviour is described by a ClassifierSet.

Returns:
null for this class (should be overriden by subclasses)
See Also:
AgentClassifier.behaviour, ClassifierSet

getBehaviour

public ClassifierSet getBehaviour(int i)
Get the classifier set representing the behaviour of the Agent.

Parameters:
i -
Returns:

getCoordNearTo

public java.awt.geom.Point2D getCoordNearTo(Entity otherEntity)
Return the closest point of the Agent to another Entity

Overrides:
getCoordNearTo in class Entity
See Also:
Entity.getCoordNearTo(Entity)

toString

public java.lang.String toString()
Creates a String describing the Agent

Overrides:
toString in class Entity