edu.sc.ants
Class Thing

java.lang.Object
  |
  +--edu.sc.ants.Thing
Direct Known Subclasses:
Agent

public class Thing
extends java.lang.Object
implements java.lang.Runnable

Top-level class for all the inhabitants of the TargetShare simulation. Agents that inherit from Thing need only implement generateAction and processInput.


Field Summary
(package private)  Environment env
          my pointer to the enviroment Im in.
 boolean fixed
          true if I am being handled by user.
 double heading
           
(package private)  java.util.Vector lastInput
          the last input I received.
(package private)  double myBroadcastRange
          how far can I scream
(package private)  java.awt.Color myColor
          my color
(package private)  long myExpireWait
          the number of miliseconds that must pass before I ignore a given observation.
 int myID
          a unique ID given to me by the Environment.
(package private)  double mySensingRange
          how far I can sense
(package private)  double mySize
          my size.
 java.lang.String name
          for printing purposes.
(package private)  boolean running
          True if this thread should be running
(package private)  boolean suspended
          Should this agent just wait?
 java.lang.String type
          my type.
 double xLocation
          where I think I am
 double yLocation
          where I think I am
 
Constructor Summary
Thing(int id, Environment e, java.lang.String n, double x, double y, double h, java.lang.String t)
          Constructor.
 
Method Summary
 void draw(java.awt.Graphics g)
          I draw myself, where I think I am.
 void draw(java.awt.Graphics g, double xl, double yl, double heading)
          I draw myself on g, using the given coordinates.
(package private)  void expireObservations()
          Expires old observations, older than myExpireWait.
 Action generateAction()
          This routine is meant to be redefined by the programmer.
(package private)  void incorporateObservations(java.util.Vector vo)
          Merge vo into lastInput Observations, using agentID as the unique key.
(package private)  void incorporateOthersObservations(Map m)
          Incorporate the observations made by (possibly) others.
 void processInput()
          This routine is meant to be redefined by the programmer.
 void resume()
          Tell this thing to continue executing its run() loop
 void run()
          The main loop.
 void start()
          the thread starts running
 void stop()
          Tell this Thing to exit its run method
 void suspend()
          Tell this thing to wait and to nothing in its run loop
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

myID

public int myID
a unique ID given to me by the Environment.

type

public java.lang.String type
my type. e.g. agent, enemy, rock

name

public java.lang.String name
for printing purposes.

env

Environment env
my pointer to the enviroment Im in.

xLocation

public double xLocation
where I think I am

yLocation

public double yLocation
where I think I am

heading

public double heading

lastInput

java.util.Vector lastInput
the last input I received. It is a vector of Observation. @see Observation

fixed

public boolean fixed
true if I am being handled by user.

myColor

java.awt.Color myColor
my color

mySize

double mySize
my size. For drawing purposes only

mySensingRange

double mySensingRange
how far I can sense

myBroadcastRange

double myBroadcastRange
how far can I scream

myExpireWait

long myExpireWait
the number of miliseconds that must pass before I ignore a given observation.

running

boolean running
True if this thread should be running

suspended

boolean suspended
Should this agent just wait?
Constructor Detail

Thing

public Thing(int id,
             Environment e,
             java.lang.String n,
             double x,
             double y,
             double h,
             java.lang.String t)
Constructor.
Parameters:
id - my unique ID.
e - the enviroment on which I reside
n - name
x - x location on the panel
y - y location on the panel
h - heading
t - type
Method Detail

stop

public void stop()
Tell this Thing to exit its run method

suspend

public void suspend()
Tell this thing to wait and to nothing in its run loop

resume

public void resume()
Tell this thing to continue executing its run() loop

start

public void start()
the thread starts running

processInput

public void processInput()
This routine is meant to be redefined by the programmer. It needs to process all the input that the agent receives. Typically, it shoudl leave a map of the agent's observations in lastInput

generateAction

public Action generateAction()
This routine is meant to be redefined by the programmer.
Returns:
the action the agent should take, given the lastInput.

run

public final void run()
The main loop. We just loop around, calling processInput and generateAction, and then taking this action in the environment
Specified by:
run in interface java.lang.Runnable

draw

public void draw(java.awt.Graphics g,
                 double xl,
                 double yl,
                 double heading)
I draw myself on g, using the given coordinates. The environment calls this function.
Parameters:
g - the Graphics object on which to draw myself.

draw

public void draw(java.awt.Graphics g)
I draw myself, where I think I am.

expireObservations

void expireObservations()
Expires old observations, older than myExpireWait.
See Also:
myExpireWait

incorporateObservations

void incorporateObservations(java.util.Vector vo)
Merge vo into lastInput Observations, using agentID as the unique key. Bayesian nets will do this better.
Parameters:
vo - vector of @bservation

incorporateOthersObservations

void incorporateOthersObservations(Map m)
Incorporate the observations made by (possibly) others. Later versions should take into account who made the observation (Bayes net).