morey.spore
Class Processor

java.lang.Object
  |
  +--morey.spore.Processor

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

Processor is the "Central Brain" for Spore War. Eventhough Spore War is a decentralized system, the Central Brain will be used to keep things fairly reproducible. I beleive that there will be timing issues that I will eventually have to deal with like if two near by polygons move at the exact time what is the result. At this point the Processor will have unpredictable results. For now, I'm willing to live with that.

Team assignments (the integer numbers...) ....How is it done?

This first kick at the can will have:

Here is a link to the source code

See Also:
SporeListener, Spore, SporeAction

Field Summary
static double BOARD_SIZE
          the default board size
 double boardSize
          the board size
protected  ProximityList claims
          a spatial list of the current claims (to test for collisions)
protected  java.util.Vector controlListeners
          a list of Objects listening to the control actions of the Processor
protected static int numOfTeams
          A constant fo the upper limit of teams
protected  java.util.Hashtable programs
          a list of spore programs that the Processor knows
protected  boolean rebuildTeamList
          a list of Objects listening to SporeEvents
protected  int runVersion
          holds the version of this run
protected  java.util.Vector sporeListeners
          a list of Objects listening to SporeEvents
protected  ProximityList spores
          a spatial list of the live spore (to test for collisions)
protected  Heap teamList
          the list of all the active teams.
protected  Team[] teams
          the list of Teams
protected  double time
          the current processor time
 
Constructor Summary
Processor()
          Construct the Processor with BOARD_SIZE size
Processor(double boardSize)
          Construct the Processor with a particular size
 
Method Summary
protected  void add(double x, double y, double angle, java.lang.String prog, int team)
           
protected  void addCode(java.io.StreamTokenizer st)
          puts the "program" from the code into the Processor
 void addControlListener(ControlListener cl)
          adds a ControlListener from the list of listeners
 void addSpore(Spore s)
          adds a spore to the processList
 void addSporeListener(SporeListener sl)
          adds a SporeListener from the list of listeners
 boolean claim(Spore s)
          puts a spore's claim to the territory
 void clear()
           
 void clearBoard()
          removes all the current claims and spores from the Processor
 boolean enter(Spore s)
          has a spore enter new territory.
 double getBoardSize()
          the accessor to the boardSize
 java.util.Iterator getOrderedSpores()
          gets the names of the programs on the list.
 java.util.Enumeration getPrograms()
          gets the names of the programs on the list.
 Spore getSpore(java.lang.String name)
           
 java.util.Stack getStack(java.lang.String name)
          gets a "program" from the programs list.
 double getTime()
          gets the current "processor" time (an internal time that has little to do with real time).
protected  void init()
          initialize the Processor
 void leave(Spore s)
          has a spore leave it's territory.
protected  void load(java.lang.String filename)
          loads a file into the content field of this SimpleWall.
 void processNext()
          processes the next spore.
 void putProgram(java.lang.String name, Spore s, boolean force)
          adds a "program" to the programs list.
 void removeControlListener(ControlListener cl)
          remove a ControlListener from the list of listeners
 void removePrograms()
          removes all the currently loaded programs from the Processor
 void removeSporeListener(SporeListener sl)
          remove a SporeListener from the list of listeners
 void run()
          runs the Processor on the processList
 void sporeUpdate(SporeEventObject se)
          tells of the SporeListeners of the SporeEvent
 void step()
           
 void stop()
          stop the current run
 void updateActions(java.lang.String action)
          tells of the ControlListeners of the new action done on the Processor
 void updateProgram(java.lang.String programs)
          tells of the ControlListeners of the on the Processor
 void updateState(int state)
          tells of the ControlListeners of the new action Processor state
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BOARD_SIZE

public static final double BOARD_SIZE
the default board size

boardSize

public final double boardSize
the board size

programs

protected java.util.Hashtable programs
a list of spore programs that the Processor knows

time

protected double time
the current processor time

runVersion

protected int runVersion
holds the version of this run

teamList

protected Heap teamList
the list of all the active teams.

spores

protected ProximityList spores
a spatial list of the live spore (to test for collisions)

claims

protected ProximityList claims
a spatial list of the current claims (to test for collisions)

teams

protected Team[] teams
the list of Teams

numOfTeams

protected static final int numOfTeams
A constant fo the upper limit of teams

sporeListeners

protected transient java.util.Vector sporeListeners
a list of Objects listening to SporeEvents

controlListeners

protected transient java.util.Vector controlListeners
a list of Objects listening to the control actions of the Processor

rebuildTeamList

protected boolean rebuildTeamList
a list of Objects listening to SporeEvents
Constructor Detail

Processor

public Processor(double boardSize)
Construct the Processor with a particular size

Parameters:
boardSize - the size of the board

Processor

public Processor()
Construct the Processor with BOARD_SIZE size
Method Detail

init

protected void init()
initialize the Processor

run

public void run()
runs the Processor on the processList
Specified by:
run in interface java.lang.Runnable

processNext

public void processNext()
processes the next spore. The time will be updated to when the spore wanted to run.

getTime

public double getTime()
gets the current "processor" time (an internal time that has little to do with real time).

claim

public boolean claim(Spore s)
puts a spore's claim to the territory
Parameters:
s - - a spore that wants to claim new space

leave

public void leave(Spore s)
has a spore leave it's territory.
Parameters:
s - - a spore that will leave it's old space

enter

public boolean enter(Spore s)
has a spore enter new territory.
Parameters:
s - - a spore that will enter a new space

getStack

public java.util.Stack getStack(java.lang.String name)
gets a "program" from the programs list.

getSpore

public Spore getSpore(java.lang.String name)

getPrograms

public java.util.Enumeration getPrograms()
gets the names of the programs on the list.

getOrderedSpores

public java.util.Iterator getOrderedSpores()
gets the names of the programs on the list.

removePrograms

public void removePrograms()
removes all the currently loaded programs from the Processor

clearBoard

public void clearBoard()
removes all the current claims and spores from the Processor

putProgram

public void putProgram(java.lang.String name,
                       Spore s,
                       boolean force)
                throws DuplicateCodeException
adds a "program" to the programs list.
Parameters:
name - the name of this program
s - an example spore that will be the template for spawning
force - if true it will replace existing programs with the same name
Throws:
DuplicateCodeException - is thrown when a spore name is already used

addSpore

public void addSpore(Spore s)
adds a spore to the processList
Parameters:
s - - a spore to be added to the processList

stop

public void stop()
stop the current run

getBoardSize

public double getBoardSize()
the accessor to the boardSize
Returns:
the size of the board from wall to wall

addSporeListener

public void addSporeListener(SporeListener sl)
adds a SporeListener from the list of listeners
Parameters:
sl - - a sporeListener that wants to hear about the sporeEvents generated by this processor

removeSporeListener

public void removeSporeListener(SporeListener sl)
remove a SporeListener from the list of listeners
Parameters:
sl - - a sporeListener that wants to be removed from the list of Listeners

sporeUpdate

public void sporeUpdate(SporeEventObject se)
tells of the SporeListeners of the SporeEvent
Parameters:
se - - the sporeEvent to be shared with all the SporeListeners

addControlListener

public void addControlListener(ControlListener cl)
adds a ControlListener from the list of listeners
Parameters:
cl - - a controlListener that wants to hear about this processor

removeControlListener

public void removeControlListener(ControlListener cl)
remove a ControlListener from the list of listeners
Parameters:
cl - - a ControlListener that wants to be removed from the list of Listeners

updateProgram

public void updateProgram(java.lang.String programs)
tells of the ControlListeners of the on the Processor
Parameters:
programs - the programs on the Processor

updateActions

public void updateActions(java.lang.String action)
tells of the ControlListeners of the new action done on the Processor
Parameters:
action - the new action done on the Processor

updateState

public void updateState(int state)
tells of the ControlListeners of the new action Processor state
Parameters:
action - the new action done on the Processor

addCode

protected void addCode(java.io.StreamTokenizer st)
puts the "program" from the code into the Processor
Parameters:
code - - the unparsed (genetic) code for a spore

load

protected void load(java.lang.String filename)
loads a file into the content field of this SimpleWall. There a few checks to see if it's a filename or URL
Parameters:
filename - - the file name / URL where thet codes will be found

step

public void step()

add

protected void add(double x,
                   double y,
                   double angle,
                   java.lang.String prog,
                   int team)

clear

public void clear()