sema
Class Agent

java.lang.Object
  extended bysema.Element
      extended bysema.Agent
All Implemented Interfaces:
java.lang.Comparable
Direct Known Subclasses:
CommunicatingAgent, EatableAgent, EatingAgent, GrowingAgent, MovingAgent, NewAgent, PheromoneUserAgent, ReceptiveAgent, SeeingAgent

public class Agent
extends Element

Basic agent, designed to easily model specific behaviours. Extends Element and contains the fundamental nested Agent.Action class. This Agent class is the basic shape for every agent able to undertake actions.


Nested Class Summary
 class Agent.Action
          Basic action of an agent.
 
Nested classes inherited from class sema.Element
Element.ElementEvent
 
Field Summary
 
Fields inherited from class sema.Element
id, world
 
Constructor Summary
Agent(World world, Area area, float delay, java.awt.Image image)
          Creates a new agent in the specified world, and registers it to this world.
 
Method Summary
protected  boolean acceptAction(Agent.Action action)
          Global internal heuristic method of decision as to the actions to undertake.
 float getDelay()
          Returns the caracteristic delay of the agent.
protected  void registerAction(Agent.Action a)
          Registers an action.
protected  void setDelay(float delay)
          Sets the caracteristic delay of the agent.
protected  void unregisterAction(Agent.Action a)
          Unregisters an action.
 
Methods inherited from class sema.Element
canTake, compareTo, death, draw, getArea, getDrawingPriority, getHeight, getIcon, getImage, getKind, getName, getProperties, highlight, highlight, isMarked, kill, setDrawingPriority, setHeight, setKind, setMarked, setProperties, toString, union
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Agent

public Agent(World world,
             Area area,
             float delay,
             java.awt.Image image)
Creates a new agent in the specified world, and registers it to this world. The caracteristic delay is the delay of reaction of the agent, in simulated unit. It's used as a default value when reacting to a stimulus or making an action.

Parameters:
world - the world which it has to register to.
area - the area of its body on the map.
delay - the caracteristic delay.
image - the main image of the element (also used as an identity icon).
See Also:
Area
Method Detail

getDelay

public float getDelay()
Returns the caracteristic delay of the agent. It is typically the delay of reaction of the agent.

Returns:
the caracteristic delay of the agent.

setDelay

protected void setDelay(float delay)
Sets the caracteristic delay of the agent. This delay must be positive.

Parameters:
delay - the caracteristic delay of the agent. (must be >=0)

registerAction

protected void registerAction(Agent.Action a)
Registers an action. It is automatically called when a new action is created. It is, by default, an empty method, but it can be overrided, to give an overview of the actions to the agent.
The agent can store all his current and planned actions, which can be very usefull for the acceptAction(Agent.Action).

Parameters:
a - the action to register.

unregisterAction

protected void unregisterAction(Agent.Action a)
Unregisters an action. It is called automatically when an action is ended. It is, by default, an empty method, but it can be overrided to give an overview of the actions to the agent. @see sema.Agent#registerAction(sema.Agent.Action).

Parameters:
a - the action to unregister.

acceptAction

protected boolean acceptAction(Agent.Action action)
Global internal heuristic method of decision as to the actions to undertake. It is called before each call to an action to determinate whether it should be executed. If it returns 'false', the Agent.Action.whenRefused() method is called and the action who called acceptAction is killed. This method has an overwhelming power of decision on the action, which cannot ignore this decision. The default acceptAction method always returns true. It's designed to provide an easy-to-use main decision function to manage actions.