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

Types of units

There are two basic types of units that can exist in the world, display units and world units. Display units are drawn into the world, and can be used as placeholders in the world, but they can never move or do any calculations. Also, display units do not block other units in the world. A world unit is the basic type of unit that can move around the world, which will be described in more detail in the next section.

The unit type is specified from the result returned by the function getObjectType.

Moving in the world

The unit is the most basic object in the world. At each time step in the world a unit is asked which direction it wants to move via the function makeMove. For a moment we'll ignore the parameters to makeMove, and focus on the calling conventions. When asked to make a move, a unit must return the direction it would like to move, one of: kN, kNE, kE, kSE, kS, kSW, kW, kNW. Additionally, if the unit does not wish to move, it can return kStay. And, if the unit is allowed to teleport, it can return kTeleport.

After returing a value from makeMove, the unit simulation verifies that the move is legal, and then calls updateLocation on the unit, informing the unit of its current location and whether the previous move was successful or not. If a unit returns kTeleport the simulation will call getLocation on the unit and move the unit directly to the returned location.

The unit simulation measures the amount of thinking time used by each unit in both the makeMove and setLocation functions. Details of how these measurements are used can be found in Simulations.

Map and Reservation providers

When a unit is asked to move it is provided with a map provider and a reservation provider. A map provider can return both a map of the world and an abstract map of the world. The unit can locate itself on the map and use that information to do any planning in the map world. The maps are not guaranteed to be exact representations of the world. For instance, if a unit is exploring the world the map may change as new parts of the world are explored.

Similarly, a reservation provider can provide information about the other units in the world and make reservations for paths the unit would like to travel. But, like the maps, the information provided by the reservation provider may not be completely accurate. A unit, for instance, may only know about the other units in his vicinity, or reservations may only be shared by a select group of units. There is no default implementation for reservations, so units will always successfully make their reservations.

Provided unit implementations

The file unit.h declares the basic unit class, as well as a few simple implementations: a teleporting unit, a randomly moving unit, and a unit that uses the right-hand-rule to walk around the world. (Note that if the right-hand-rule unit is not next to a wall it will just walk in cicles.)

In the shared directory more one useful unit class is defined: a search unit. The search unit takes a search algorithm as a parameter. This unit asks the search algorithm to plan a path for the unit, and then caches the path returned by the unit, executing it one step at a time in the world.

Prev: Overview Next: Unit-Groups


Generated on Tue Aug 18 03:46:10 2009 for HOG by doxygen 1.3.4