demo.helicopter
Class Referee

java.lang.Object
  extended byjava.lang.Thread
      extended bydemo.helicopter.Referee
All Implemented Interfaces:
java.lang.Runnable

public class Referee
extends java.lang.Thread

The referee monitors the execution of the simulation. It receives all state PDUs, maintains each entities information, and performs the necessary actions to update the visual simulation. It enforces the rules of the simulation, awarding points as appropriate and reseting the simulation whenever a team return the opposing teams' flag to it's homebase. The Referee directly controls the state of the team flags.


Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Referee()
          Constructor.
 
Method Summary
 void blueReleaseFlag()
          Called when the blue flag is released by a 'red' entity
 void checkForPickupBlue(EntityStatePdu vehicle)
          Determines if the given PDU is from a 'red' entity.
 void checkForPickupRed(EntityStatePdu vehicle)
          Determines if the given PDu is from a 'blue' entity.
 void checkForVictory()
          Check to see if either flag is currently taken by the opposing team.
 void collectPdus()
          Collects the incoming PDUs and performs the appropriate updates
protected  void debug(java.lang.String pDiagnostic)
          Debugging output routine.
 boolean getDEBUG()
          Access DEBUG trace variable.
static void main(java.lang.String[] args)
          The 'Main' method of the simulation.
 void moveBlue(EntityStatePdu vehicle)
          Visually updates the current information for any 'blue' entity, based upon the given PDU
 void moveRed(EntityStatePdu vehicle)
          Visually updates the current information for any 'red' entity, based upon the given PDU
 void redReleaseFlag()
          Called when the red flag is released by a blue entity
 void reset()
          Resets the simulation for another run
 void run()
          Called to begins the Referee thread.
 void runAgents(EntityStatePdu pEntityStatePdu)
          Keep's track of the non-human controlled agent entities.
 void setDEBUG(boolean pDEBUG)
          Modify DEBUG trace variable.
 void setPlaying(boolean setValue)
          Used to toggle the 'playing' boolean.
 void startPlaying()
          Called to initiate the running of the simulation.
 void stopRun()
          Terminates the behaviorSreamBuffer
protected  void trace(java.lang.String pDiagnostic)
          Guaranteed trace output routine.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Referee

public Referee()
Constructor. Instantiates the referee entity that monotors the simulation.

Method Detail

getDEBUG

public boolean getDEBUG()
Access DEBUG trace variable.


setDEBUG

public void setDEBUG(boolean pDEBUG)
Modify DEBUG trace variable.


debug

protected void debug(java.lang.String pDiagnostic)
Debugging output routine. Pass in a string, and it gets printed out on the console. You can pass in strings such as "foo " + bar.getName(). Text output appears in the Java Console (CosmoPlayer browser) or in the VRML console (WorldView browser).


trace

protected void trace(java.lang.String pDiagnostic)
Guaranteed trace output routine. Pass in a string, and it gets printed out on the console. You can pass in strings such as "foo " + bar.getName(). Text output appears in the Java Console (CosmoPlayer browser) or in the VRML console (WorldView browser).

Can't be static or all entities look the same.


run

public void run()
Called to begins the Referee thread. initiates the sending of PDUs


setPlaying

public void setPlaying(boolean setValue)
Used to toggle the 'playing' boolean. True = the simulation is running

Returns:
void

startPlaying

public void startPlaying()
Called to initiate the running of the simulation.

Returns:
void

stopRun

public void stopRun()
Terminates the behaviorSreamBuffer

Returns:
void

reset

public void reset()
Resets the simulation for another run

Returns:
void

redReleaseFlag

public void redReleaseFlag()
Called when the red flag is released by a blue entity

Returns:
void

blueReleaseFlag

public void blueReleaseFlag()
Called when the blue flag is released by a 'red' entity

Returns:
void

moveRed

public void moveRed(EntityStatePdu vehicle)
Visually updates the current information for any 'red' entity, based upon the given PDU

Returns:
void

moveBlue

public void moveBlue(EntityStatePdu vehicle)
Visually updates the current information for any 'blue' entity, based upon the given PDU

Returns:
void

collectPdus

public void collectPdus()
Collects the incoming PDUs and performs the appropriate updates

Returns:
void

checkForPickupRed

public void checkForPickupRed(EntityStatePdu vehicle)
Determines if the given PDu is from a 'blue' entity. If it is, this method checks to see if the entity is 'close enough' to the 'red' flag to consider it 'picked-up'

Returns:
void

checkForPickupBlue

public void checkForPickupBlue(EntityStatePdu vehicle)
Determines if the given PDU is from a 'red' entity. If it is, this method checks to see if the entity is 'close enough' to the 'blue' flag to consider it 'picked-up'

Returns:
void

checkForVictory

public void checkForVictory()
Check to see if either flag is currently taken by the opposing team. If it is, the method determines the flags location in relation to the opposing team's 'home' base, to determine if a victory has occurred. If so, the total number of victories for that team is accumulated. If the total is less than two, the simulation is reset and the next attempt begins. If the total is equal to two, the simulation is fully reset and the game starts over.

Returns:
void

runAgents

public void runAgents(EntityStatePdu pEntityStatePdu)
Keep's track of the non-human controlled agent entities. If the given PDU is from an agent entity, first it is checked to see if the entity already exists. If it doesn't, it is added to the appropriate Hashtable, and tested for relationships with other agents. The appropriate relationships are then formed. Finally, if the agent is in a relationship, and DataPDU is sent

Returns:
void

main

public static void main(java.lang.String[] args)
The 'Main' method of the simulation. Parses the passes arguments and sets the simulation variables based on the provided argumanets. A 'Referee' is then instantiated and the simulation is initiated. The possible arguments are: 'rtp' 'trace' 'ttl' or 'timeToLive' + int (0-127) (eg: ttl 120) 'pause' or 'sleep' or 'wait' + int (0-60) (eg: sleep 45)