rescuecore
Class Agent

java.lang.Object
  extended byrescuecore.Agent
All Implemented Interfaces:
RescueConstants
Direct Known Subclasses:
CenterAgent, DummyAgent, PlatoonAgent

public abstract class Agent
extends java.lang.Object
implements RescueConstants

This is the base class for all agents. This class handles messages from the server, provides a memory of the simulation environment and convenience methods for path planning etc. This class also enforces the message limits imposed by the robocup rescue rules.

Agent implementations should provide at least one of the following three constructors:

  1. A no-arg constructor - e.g. MyAgent()
  2. A String[] constructor - e.g. MyAgent(String[] args)
  3. A constructor that takes one or more String arguments - e.g. MyAgent(String arg1, String arg2)
The reason for this is that the AgentSystem allows arguments to be passed to the Agent via the command line. When creating an instance of the agent it first looks for any constructor that accepts the right number of String arguments, followed by the String[] constructor. Failing that, the no-arg constructor will be used.

For example, if the command line provides two arguments then the AgentSystem will use the MyAgent(String arg1, String arg2) constructor. If only one argument is provided then the MyAgent(String[] args) constructor is used.


Field Summary
protected  AgentSystem agentSystem
           
protected  int agentType
           
protected  int id
           
protected  Memory memory
           
protected  int timeStep
           
protected  int type
           
 
Fields inherited from interface rescuecore.RescueConstants
AGENT_TYPE_AMBULANCE_CENTER, AGENT_TYPE_AMBULANCE_TEAM, AGENT_TYPE_ANY, AGENT_TYPE_ANY_AGENT, AGENT_TYPE_ANY_BUILDING, AGENT_TYPE_ANY_MOBILE, AGENT_TYPE_CIVILIAN, AGENT_TYPE_FIRE_BRIGADE, AGENT_TYPE_FIRE_STATION, AGENT_TYPE_POLICE_FORCE, AGENT_TYPE_POLICE_OFFICE, AK_ACKNOWLEDGE, AK_CLEAR, AK_CONNECT, AK_EXTINGUISH, AK_LOAD, AK_MOVE, AK_RESCUE, AK_REST, AK_SAY, AK_TELL, AK_UNLOAD, BYTE_SIZE, COMMAND_ACKNOWLEDGE, COMMAND_CLEAR, COMMAND_CONNECT, COMMAND_EXTINGUISH, COMMAND_LOAD, COMMAND_MOVE, COMMAND_RESCUE, COMMAND_REST, COMMAND_SAY, COMMAND_TELL, COMMAND_UNLOAD, FIERYNESS_BURNING, FIERYNESS_BURNT_OUT, FIERYNESS_HEATING, FIERYNESS_INFERNO, FIERYNESS_MODERATELY_BURNT, FIERYNESS_NOT_BURNT, FIERYNESS_SLIGHTLY_BURNT, FIERYNESS_VERY_BURNT, GK_CONNECT_ERROR, GK_CONNECT_OK, HEADER_NULL, INT_SIZE, INTERNAL_TYPE_AMBULANCE_CENTER, INTERNAL_TYPE_AMBULANCE_TEAM, INTERNAL_TYPE_ANY_BUILDING, INTERNAL_TYPE_ANY_HUMANOID, INTERNAL_TYPE_ANY_PLATOON, INTERNAL_TYPE_BUILDING, INTERNAL_TYPE_CAR, INTERNAL_TYPE_CIVILIAN, INTERNAL_TYPE_FIRE_BRIGADE, INTERNAL_TYPE_FIRE_STATION, INTERNAL_TYPE_NODE, INTERNAL_TYPE_POLICE_FORCE, INTERNAL_TYPE_POLICE_OFFICE, INTERNAL_TYPE_REFUGE, INTERNAL_TYPE_RIVER, INTERNAL_TYPE_RIVER_NODE, INTERNAL_TYPE_ROAD, INTERNAL_TYPE_WORLD, KA_CONNECT_ERROR, KA_CONNECT_OK, KA_HEAR, KA_SENSE, KG_ACKNOWLEDGE, KG_CONNECT, KG_UPDATE, KS_COMMANDS, KS_CONNECT_ERROR, KS_CONNECT_OK, KS_UPDATE, KV_CONNECT_ERROR, KV_CONNECT_OK, KV_UPDATE, MAX_CENTER_MESSAGES, MAX_EXTINGUISH_DISTANCE, MAX_EXTINGUISH_POWER, MAX_HP, MAX_PLATOON_MESSAGES, MAX_RESCUE_DISTANCE, MAX_WATER, PROPERTY_BLOCK, PROPERTY_BROKENNESS, PROPERTY_BUILDING_APEXES, PROPERTY_BUILDING_AREA_GROUND, PROPERTY_BUILDING_AREA_TOTAL, PROPERTY_BUILDING_ATTRIBUTES, PROPERTY_BUILDING_CODE, PROPERTY_BUILDING_SHAPE_ID, PROPERTY_BURIEDNESS, PROPERTY_CARS_PASS_TO_HEAD, PROPERTY_CARS_PASS_TO_TAIL, PROPERTY_DAMAGE, PROPERTY_DIRECTION, PROPERTY_EDGES, PROPERTY_ENTRANCES, PROPERTY_FIERYNESS, PROPERTY_FLOORS, PROPERTY_HEAD, PROPERTY_HP, PROPERTY_HUMANS_PASS_TO_HEAD, PROPERTY_HUMANS_PASS_TO_TAIL, PROPERTY_IGNITION, PROPERTY_LATITUDE, PROPERTY_LENGTH, PROPERTY_LINES_TO_HEAD, PROPERTY_LINES_TO_TAIL, PROPERTY_LONGITUDE, PROPERTY_MAX, PROPERTY_MEDIAN_STRIP, PROPERTY_NULL, PROPERTY_POCKET_TO_TURN_ACROSS, PROPERTY_POSITION, PROPERTY_POSITION_EXTRA, PROPERTY_POSITION_HISTORY, PROPERTY_REPAIR_COST, PROPERTY_ROAD_KIND, PROPERTY_SHORTCUT_TO_TURN, PROPERTY_SIGNAL, PROPERTY_SIGNAL_TIMING, PROPERTY_STAMINA, PROPERTY_START_TIME, PROPERTY_STRETCHED_LENGTH, PROPERTY_TAIL, PROPERTY_TYPE_BOOLEAN, PROPERTY_TYPE_INT, PROPERTY_TYPE_INT_ARRAY, PROPERTY_WATER_QUANTITY, PROPERTY_WIDTH, PROPERTY_WIDTH_FOR_WALKERS, PROPERTY_WIND_DIRECTION, PROPERTY_WIND_FORCE, PROPERTY_X, PROPERTY_Y, SAY_LENGTH, SHORT_SIZE, SK_ACKNOWLEDGE, SK_CONNECT, SK_UPDATE, TELL_LENGTH, TYPE_AMBULANCE_CENTER, TYPE_AMBULANCE_TEAM, TYPE_BUILDING, TYPE_CAR, TYPE_CIVILIAN, TYPE_FIRE_BRIGADE, TYPE_FIRE_STATION, TYPE_NODE, TYPE_NULL, TYPE_POLICE_FORCE, TYPE_POLICE_OFFICE, TYPE_REFUGE, TYPE_RIVER, TYPE_RIVER_NODE, TYPE_ROAD, TYPE_WORLD, VK_ACKNOWLEDGE, VK_CONNECT
 
Constructor Summary
protected Agent(int type)
          Create a new agent of a particular type.
 
Method Summary
protected  void appendCommand(Command c)
          Add a Command to our current set of Commands to be sent to the kernel.
protected  void flushCommands()
          Send all our buffered commands to the kernel
protected  Memory generateMemory()
          Construct a new Memory object for use by this Agent.
protected  AgentSystem getAgentSystem()
          Get the AgentSystem used for message passing
 int getAgentType()
          Get this agent's type
 int getID()
          Get this agent's unique id, assigned by the kernel
protected  int getMaxReceive()
          How many messages can this agent receive per timestep?
protected  int getMaxSend()
          How many messages can this agent send per timestep?
 Memory getMemory()
          Get this agents Memory
 int getType()
          Get the type of RescueObject that this agent represents
 void handleHear(int from, byte[] msg)
          Handle a KA_HEAR message
 void handleSense(java.io.DataInput in, int timeStep)
          Handle a KA_SENSE message
protected abstract  boolean hear(int from, byte[] msg)
          Called after a KA_HEAR is received
 void initialise(AgentSystem system, int id, RescueObject[] knowledge, RescueObject self)
          Initialise this agent
protected  void log(java.lang.String message)
          Log a message - the message will be prepended with "Agent : :"
protected  void say(byte[] message)
          Send an AK_SAY message to the kernel.
protected abstract  void sense()
          Called after a KA_SENSE is received
protected  void tell(byte[] message)
          Send an AK_TELL message to the kernel.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

agentSystem

protected AgentSystem agentSystem

type

protected int type

agentType

protected int agentType

id

protected int id

memory

protected Memory memory

timeStep

protected int timeStep
Constructor Detail

Agent

protected Agent(int type)
Create a new agent of a particular type.

Parameters:
type - The type of this agent - this value should be the logical OR of all types that this agent can be. For example, an Agent implementation that can be either a Police Force or an Ambulance Team should specify its type as AGENT_TYPE_POLICE_FORCE | AGENT_TYPE_AMBULANCE_TEAM.
See Also:
RescueConstants.AGENT_TYPE_CIVILIAN, RescueConstants.AGENT_TYPE_FIRE_BRIGADE, RescueConstants.AGENT_TYPE_FIRE_STATION, RescueConstants.AGENT_TYPE_POLICE_FORCE, RescueConstants.AGENT_TYPE_POLICE_OFFICE, RescueConstants.AGENT_TYPE_AMBULANCE_TEAM, RescueConstants.AGENT_TYPE_AMBULANCE_CENTER, RescueConstants.AGENT_TYPE_ANY_MOBILE, RescueConstants.AGENT_TYPE_ANY_BUILDING, RescueConstants.AGENT_TYPE_ANY_AGENT, RescueConstants.AGENT_TYPE_ANY
Method Detail

toString

public java.lang.String toString()

getMemory

public final Memory getMemory()
Get this agents Memory

Returns:
The agents Memory

getType

public final int getType()
Get the type of RescueObject that this agent represents

See Also:
RescueConstants.TYPE_CIVILIAN, RescueConstants.TYPE_CAR, RescueConstants.TYPE_FIRE_BRIGADE, RescueConstants.TYPE_FIRE_STATION, RescueConstants.TYPE_POLICE_FORCE, RescueConstants.TYPE_POLICE_OFFICE, RescueConstants.TYPE_AMBULANCE_TEAM, RescueConstants.TYPE_AMBULANCE_CENTER

getAgentType

public final int getAgentType()
Get this agent's type

See Also:
RescueConstants.AGENT_TYPE_CIVILIAN, RescueConstants.AGENT_TYPE_FIRE_BRIGADE, RescueConstants.AGENT_TYPE_FIRE_STATION, RescueConstants.AGENT_TYPE_POLICE_FORCE, RescueConstants.AGENT_TYPE_POLICE_OFFICE, RescueConstants.AGENT_TYPE_AMBULANCE_TEAM, RescueConstants.AGENT_TYPE_AMBULANCE_CENTER

getID

public final int getID()
Get this agent's unique id, assigned by the kernel


initialise

public void initialise(AgentSystem system,
                       int id,
                       RescueObject[] knowledge,
                       RescueObject self)
Initialise this agent

Parameters:
system - The AgentSystem controlling this agent
id - This agent's kernel-assigned id
knowledge - This agent's knowledge of the world
self - The RescueObject describing this agent

generateMemory

protected Memory generateMemory()
Construct a new Memory object for use by this Agent. This method allows Agents to customise their choice of Memory object. The default implementation returns an ArrayMemory.

Returns:
A new Memory object

log

protected final void log(java.lang.String message)
Log a message - the message will be prepended with "Agent : :"

Parameters:
message - The message to log

getAgentSystem

protected final AgentSystem getAgentSystem()
Get the AgentSystem used for message passing

Returns:
This agent's controlling AgentSystem

sense

protected abstract void sense()
Called after a KA_SENSE is received


hear

protected abstract boolean hear(int from,
                                byte[] msg)
Called after a KA_HEAR is received

Parameters:
from - The agent that sent the message
msg - The message body
Returns:
true iff this agent decided to hear the message

getMaxSend

protected final int getMaxSend()
How many messages can this agent send per timestep?

Returns:
The maximum number of messages this agent can send per timestep

getMaxReceive

protected final int getMaxReceive()
How many messages can this agent receive per timestep?

Returns:
The maximum number of messages this agent can receive per timestep

appendCommand

protected void appendCommand(Command c)
Add a Command to our current set of Commands to be sent to the kernel. Commands will be buffered until @{link #flushCommands()} is called.

Parameters:
c - The next Command to send.

flushCommands

protected void flushCommands()
Send all our buffered commands to the kernel


say

protected final void say(byte[] message)
Send an AK_SAY message to the kernel. If this agent has already send too many messages this timestep then this will be silently ignored

Parameters:
message - The message

tell

protected final void tell(byte[] message)
Send an AK_TELL message to the kernel. If this agent has already send too many messages this timestep then this will be silently ignored

Parameters:
message - The message

handleSense

public final void handleSense(java.io.DataInput in,
                              int timeStep)
                       throws UnknownTypeException,
                              UnknownPropertyException,
                              java.io.IOException
Handle a KA_SENSE message

Parameters:
in - The DataInput to read the sense from
timeStep - The timestep of the sense message
Throws:
UnknownTypeException - if an unknown object type appears
UnknownPropertyException - if an unknown property shows up
java.io.IOException - if an IO problem occurs

handleHear

public final void handleHear(int from,
                             byte[] msg)
Handle a KA_HEAR message

Parameters:
from - Who the message is from
msg - The body of the AK_SAY or AK_TELL message