|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectrescuecore.Agent
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:
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
|
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 |
protected AgentSystem agentSystem
protected int type
protected int agentType
protected int id
protected Memory memory
protected int timeStep
Constructor Detail |
protected Agent(int type)
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.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 |
public java.lang.String toString()
public final Memory getMemory()
public final int getType()
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
public final int getAgentType()
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
public final int getID()
public void initialise(AgentSystem system, int id, RescueObject[] knowledge, RescueObject self)
system
- The AgentSystem controlling this agentid
- This agent's kernel-assigned idknowledge
- This agent's knowledge of the worldself
- The RescueObject describing this agentprotected Memory generateMemory()
ArrayMemory
.
protected final void log(java.lang.String message)
message
- The message to logprotected final AgentSystem getAgentSystem()
protected abstract void sense()
protected abstract boolean hear(int from, byte[] msg)
from
- The agent that sent the messagemsg
- The message body
protected final int getMaxSend()
protected final int getMaxReceive()
protected void appendCommand(Command c)
c
- The next Command to send.protected void flushCommands()
protected final void say(byte[] message)
message
- The messageprotected final void tell(byte[] message)
message
- The messagepublic final void handleSense(java.io.DataInput in, int timeStep) throws UnknownTypeException, UnknownPropertyException, java.io.IOException
in
- The DataInput to read the sense fromtimeStep
- The timestep of the sense message
UnknownTypeException
- if an unknown object type appears
UnknownPropertyException
- if an unknown property shows up
java.io.IOException
- if an IO problem occurspublic final void handleHear(int from, byte[] msg)
from
- Who the message is frommsg
- The body of the AK_SAY or AK_TELL message
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |