Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

unitSimulation Class Reference

The basic simulation class for the world. More...

#include <unitSimulation.h>

Inheritance diagram for unitSimulation:

Inheritance graph
[legend]
Collaboration diagram for unitSimulation:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 unitSimulation (mapAbstraction *, bool keepStats=false)
 construct a unit simulation.

virtual ~unitSimulation ()
 delete a unit simulation.

bool saveHistory (char *, bool includeMap=true)
bool loadHistory (char *)
 Load a history file into the simulation.

virtual void addUnit (unit *)
 add a unit to the simulation.

virtual void addUnit (unit *, bool block)
 add a unit to the simulation.

virtual void addUnitGroup (unitGroup *)
 Add unit group to simulation.

unitGroup * getUnitGroup (int which)
 Get the nth unit group.

unitgetUnit (int which)
 Get the nth unit.

unitfindUnit (int x, int y)
 Find a unit in the world.

bool setIgnoreOnTarget (unit *, bool)
 Set ignoreOnTatget status of nth unit.

virtual void advanceTime (double amount)
 advance time in the simulation.

void setRealTime (bool)
 Determines whether the simulation strives to run in "real" time or be more accurate.

bool getRealTime ()
void setLockstepTime (bool b)
bool getLockstepTime ()
void setAsynchronous ()
 Set if the simulation is asynchronous.

void setSynchronous ()
void setSimulationPaused (bool val)
bool getSimulationPaused ()
double getSimulationTime ()
 return the current inside the simulation

double getDisplayTime ()
 return the current time being drawn

void setDisplayTime (double val)
 Set the time currently displayed.

void offsetDisplayTime (double val)
 Offset the display time.

void openGLDraw ()
void print (bool forceOutput=true)
virtual bool done ()
 done returns true when all units/groups say they are done.

bool nodeOccupied (node *currNode)
 reservationProvider interface

bool tileOccupied (int x, int y)
virtual bool canMove (node *, node *, double, unit *)
virtual bool reserveMove (node *, node *, double, unit *)
virtual bool clearMove (node *, node *, double, unit *)
virtual void clearAllReservations ()
void clearAllUnits ()
 clear all units in simulation.

void setUseBlocking (bool val)
 turns unit blocking on and off

void setmapAbstractionDisplay (int _whichMap=kUnitSimulationMap)
 Set which map is returned from getMapAbstraction.

int getDisplayMapNumber ()
 Return which map is being currently displayed.

MapgetMap ()
 Returns the underlying map.

mapAbstractiongetMapAbstraction ()
 Returns the abstract map from the simulation.

mapAbstractiongetMapAbstraction (int _which)
 Returns the nth groups abstract map.

mapAbstractiongetMapAbstractionDisplay ()
 Returns the abstract map currently being displayed.

void cyclemapAbstractionDisplay ()
 Cycle which abstract map should be displayed.

void setPenalty (double pen)
 setPenalty for thinking.

double getPenalty ()
 getPenalty for thinking.

void toggleNoOpenGLDraw ()
 Toggle open GL display.

void setMoveStochasticity (double _stochasticity)
 set chance for move failing.

double getMoveStochasticity ()
statCollectiongetStats ()
void printCollectedStats (bool v)
void getRandomLocation (int &x, int &y, tTerrain terrain=kGround)
void getRandomLocation (int x1, int y1, int &x2, int &y2, tTerrain terrain=kGround)
 Get random location which is guaranteed to be pathable from the given location and which is not occupied by any other objects in the world so far.

void getRandomLocations (int &x1, int &y1, int &x2, int &y2, tTerrain terrain=kGround)
 Get random location which is guaranteed to be pathable and which is not occupied by any other objects in the world so far.

bool canCrossDiagonally ()
void setCanCrossDiagonally (bool cross)

Protected Member Functions

unitInfofindUnit (unit *)
virtual void doPreTimestepCalc ()
virtual void doTimestepCalc ()
virtual void doPostTimestepCalc ()
void stepUnitTime (unitInfo *)
 step time for a single unit.

void setAgentLocation (unitInfo *, bool success=false, bool timer=false)
void updateMap ()
bool updatemapAbstraction ()
void drawBlockedSquare (int x, int y)
bool findUnitDisplayTime (unitInfo *ui)

Protected Attributes

Mapmap
mapAbstractionaMap
bitVectorbv
int which_map
int map_width
int map_height
int map_revision
std::vector< unitInfo * > units
std::vector< unitInfo * > displayUnits
std::vector< unitGroup * > unitGroups
std::priority_queue< const
unitInfo *, std::vector<
unitInfo * >, unitInfoCompare
moveQ
double currTime
double viewTime
bool asynch
bool blocking
bool realTime
bool pause
bool lockstepTime
double penalty
double stochasticity
bool unitsMoved
bool disallowDiagonalCrossingMoves
double currDist
bool noOpenGLDraw
bool keepHistory
statCollection stats

Detailed Description

The basic simulation class for the world.


Constructor & Destructor Documentation

unitSimulation::unitSimulation mapAbstraction _aMap,
bool  keepStats = false
 

construct a unit simulation.

construct a unit simulation around a given map.

unitSimulation::~unitSimulation  )  [virtual]
 

delete a unit simulation.

The unit simulation will delete all units (display and otherwise) as well as all groups that have been added to the simulation.


Member Function Documentation

void unitSimulation::addUnit unit u,
bool  _blocking
[virtual]
 

add a unit to the simulation.

Adds a unit to the simulation. You can optionally set whether this unit blocks the places where it stands, which can differ from the simulation default. If the unit's current x/y location is valid, the unit will be placed there. Otherwise it will be added to a random location on the map. If a unit is part of a group, it should be added to that group before being added to the simulation.

Reimplemented in unitRaceSimulation.

void unitSimulation::addUnit unit u  )  [virtual]
 

add a unit to the simulation.

Adds a unit to the simulation. If the unit's current x/y location is valid, the unit will be placed there. Otherwise it will be added to a random location on the map. If a unit is part of a group, it should be added to that group before being added to the simulation.

Reimplemented in unitRaceSimulation.

void unitSimulation::addUnitGroup unitGroup *  ug  )  [virtual]
 

Add unit group to simulation.

Adds a unit group to the simulation. Unit groups are in simulation mostly for memory management and display purposes.

void unitSimulation::advanceTime double  amount  )  [virtual]
 

advance time in the simulation.

This is the basic function for stepping time in the simulation. The simulation will advance all units by this amount (seconds -- although really unitless) If we are in real-time mode, each unit will get one move per this time step. Otherwise, we will step units iteratively until they have all moved as often as they can in this amount of time. Once a unit returns kStay they are giving up any movement until this time step is finished.

bool unitSimulation::canCrossDiagonally  )  [inline]
 

virtual bool unitSimulation::canMove node ,
node ,
double  ,
unit
[inline, virtual]
 

Implements reservationProvider.

virtual void unitSimulation::clearAllReservations  )  [inline, virtual]
 

Implements reservationProvider.

void unitSimulation::clearAllUnits  ) 
 

clear all units in simulation.

removes and deletes all units & unit groups from the simulation.

virtual bool unitSimulation::clearMove node ,
node ,
double  ,
unit
[inline, virtual]
 

Implements reservationProvider.

void unitSimulation::cyclemapAbstractionDisplay  ) 
 

Cycle which abstract map should be displayed.

selects the next possibile abstract map to be returned from getMapAbstraction.

bool unitSimulation::done  )  [virtual]
 

done returns true when all units/groups say they are done.

For episodic tasks we may want to run a set number of times, or until learning converges, etc. This is a way of detecting this so we can stop the simulation or start a new episode.

Reimplemented in unitRaceSimulation.

void unitSimulation::doPostTimestepCalc  )  [protected, virtual]
 

void unitSimulation::doPreTimestepCalc  )  [protected, virtual]
 

Reimplemented in patUnitSimulation, and unitRaceSimulation.

void unitSimulation::doTimestepCalc  )  [protected, virtual]
 

Reimplemented in unitRaceSimulation.

void unitSimulation::drawBlockedSquare int  x,
int  y
[protected]
 

unitInfo * unitSimulation::findUnit unit  )  [protected]
 

unit * unitSimulation::findUnit int  x,
int  y
 

Find a unit in the world.

Return the unit on location x, y, if there is one. Otherwise returns NULL.

bool unitSimulation::findUnitDisplayTime unitInfo ui  )  [protected]
 

int unitSimulation::getDisplayMapNumber  )  [inline]
 

Return which map is being currently displayed.

double unitSimulation::getDisplayTime  )  [inline]
 

return the current time being drawn

bool unitSimulation::getLockstepTime  )  [inline]
 

Map* unitSimulation::getMap  )  [inline, virtual]
 

Returns the underlying map.

Implements mapProvider.

mapAbstraction * unitSimulation::getMapAbstraction int  _which  ) 
 

Returns the nth groups abstract map.

(0 is the actual map of the world.)

mapAbstraction * unitSimulation::getMapAbstraction  )  [virtual]
 

Returns the abstract map from the simulation.

Implements mapProvider.

mapAbstraction * unitSimulation::getMapAbstractionDisplay  ) 
 

Returns the abstract map currently being displayed.

double unitSimulation::getMoveStochasticity  )  [inline]
 

double unitSimulation::getPenalty  )  [inline]
 

getPenalty for thinking.

Gets the multiplier used to penalize thinking time.

void unitSimulation::getRandomLocation int  x1,
int  y1,
int &  x2,
int &  y2,
tTerrain  terrain = kGround
 

Get random location which is guaranteed to be pathable from the given location and which is not occupied by any other objects in the world so far.

void unitSimulation::getRandomLocation int &  x,
int &  y,
tTerrain  terrain = kGround
 

void unitSimulation::getRandomLocations int &  x1,
int &  y1,
int &  x2,
int &  y2,
tTerrain  terrain = kGround
 

Get random location which is guaranteed to be pathable and which is not occupied by any other objects in the world so far.

bool unitSimulation::getRealTime  )  [inline]
 

bool unitSimulation::getSimulationPaused  )  [inline]
 

double unitSimulation::getSimulationTime  )  [inline, virtual]
 

return the current inside the simulation

Implements simulationInfo.

statCollection* unitSimulation::getStats  )  [inline]
 

unit * unitSimulation::getUnit int  which  ) 
 

Get the nth unit.

unitGroup * unitSimulation::getUnitGroup int  which  ) 
 

Get the nth unit group.

bool unitSimulation::loadHistory char *  fname  ) 
 

Load a history file into the simulation.

Returns true if the history loads. Loading a history causes all units currently in the simulation to be removed and turns the history on.

bool unitSimulation::nodeOccupied node currNode  )  [inline, virtual]
 

reservationProvider interface

Implements reservationProvider.

void unitSimulation::offsetDisplayTime double  val  ) 
 

Offset the display time.

When a history is kept, this allows you to offset the displayed time. New values for the view time below 0 will be truncated to 0. Values above the current simulation time will be set to the current simulation time.

void unitSimulation::openGLDraw  ) 
 

void unitSimulation::print bool  forceOutput = true  ) 
 

void unitSimulation::printCollectedStats bool  v  )  [inline]
 

virtual bool unitSimulation::reserveMove node ,
node ,
double  ,
unit
[inline, virtual]
 

Implements reservationProvider.

bool unitSimulation::saveHistory char *  ,
bool  includeMap = true
 

void unitSimulation::setAgentLocation unitInfo ,
bool  success = false,
bool  timer = false
[protected]
 

void unitSimulation::setAsynchronous  )  [inline]
 

Set if the simulation is asynchronous.

void unitSimulation::setCanCrossDiagonally bool  cross  )  [inline]
 

void unitSimulation::setDisplayTime double  val  ) 
 

Set the time currently displayed.

When a history is kept, this allows you to shift the display to any time. Values below 0 will be truncated to 0. Values above the current simulation time will be set to the current simulation time. Ignored if history isn't being kept.

bool unitSimulation::setIgnoreOnTarget unit u,
bool  x
 

Set ignoreOnTatget status of nth unit.

void unitSimulation::setLockstepTime bool  b  )  [inline]
 

void unitSimulation::setmapAbstractionDisplay int  _whichMap = kUnitSimulationMap  ) 
 

Set which map is returned from getMapAbstraction.

if you want to view the map of one of the groups instead of the actual world, you can use thsi function to choose. The default value is the actual world map. Pass 1..n to select the 1st to nth unit group's map.

void unitSimulation::setMoveStochasticity double  _stochasticity  )  [inline]
 

set chance for move failing.

This is the chance that a move will just fail.

void unitSimulation::setPenalty double  pen  )  [inline]
 

setPenalty for thinking.

Sets the multiplier used to penalize thinking time.

void unitSimulation::setRealTime bool  _realTime  ) 
 

Determines whether the simulation strives to run in "real" time or be more accurate.

In real-time mode each unit get a maximum of 1 move each time step, and the current time for any unit is set to the current time after any time step, so that things run more in real-time.

In non-real-time mode the simulation allows units to run until they have used up all the time they are alloted. This may run as much as nx slower than real time mode, if all units are using up all their time.

If a unit wants to stay, they forfeit the rest of their turn time. This has implications when units are chasing each other around, but really helps when units are sitting around doing nothing.

void unitSimulation::setSimulationPaused bool  val  )  [inline]
 

void unitSimulation::setSynchronous  )  [inline]
 

void unitSimulation::setUseBlocking bool  val  )  [inline]
 

turns unit blocking on and off

void unitSimulation::stepUnitTime unitInfo theUnit  )  [protected]
 

step time for a single unit.

This function takes care of all the simulation details for moving a single unit, doing timing, etc. When overloading advanceTime, this function can be called for each unit that moves.

bool unitSimulation::tileOccupied int  x,
int  y
[inline]
 

void unitSimulation::toggleNoOpenGLDraw  )  [inline]
 

Toggle open GL display.

void unitSimulation::updateMap  )  [protected]
 

bool unitSimulation::updatemapAbstraction  )  [protected]
 


Member Data Documentation

mapAbstraction* unitSimulation::aMap [protected]
 

bool unitSimulation::asynch [protected]
 

bool unitSimulation::blocking [protected]
 

bitVector* unitSimulation::bv [protected]
 

double unitSimulation::currDist [protected]
 

double unitSimulation::currTime [protected]
 

bool unitSimulation::disallowDiagonalCrossingMoves [protected]
 

std::vector<unitInfo *> unitSimulation::displayUnits [protected]
 

bool unitSimulation::keepHistory [protected]
 

bool unitSimulation::lockstepTime [protected]
 

Map* unitSimulation::map [protected]
 

int unitSimulation::map_height [protected]
 

int unitSimulation::map_revision [protected]
 

int unitSimulation::map_width [protected]
 

std::priority_queue<const unitInfo*, std::vector<unitInfo *>, unitInfoCompare> unitSimulation::moveQ [protected]
 

bool unitSimulation::noOpenGLDraw [protected]
 

bool unitSimulation::pause [protected]
 

double unitSimulation::penalty [protected]
 

bool unitSimulation::realTime [protected]
 

statCollection unitSimulation::stats [protected]
 

double unitSimulation::stochasticity [protected]
 

std::vector<unitGroup *> unitSimulation::unitGroups [protected]
 

std::vector<unitInfo *> unitSimulation::units [protected]
 

bool unitSimulation::unitsMoved [protected]
 

double unitSimulation::viewTime [protected]
 

int unitSimulation::which_map [protected]
 


The documentation for this class was generated from the following files:
Generated on Tue Aug 18 03:46:10 2009 for HOG by doxygen 1.3.4