|
ProtoBot
|
(DISCONTINUED)
Unfortunately, BOIDS could not be optimized enough to be run within tournament computation time rules. However, the algorithm is still a cool implementation of a flocking algorithm for unit movement, so it is being kept in the codebase for potential future use.
More...
#include <BOIDS.h>
Static Public Member Functions | |
| static void | squadFlock (Squad *squad) |
| Main function of BOIDS flocking. Calculates leader, separation, and terrain avoidance vectors for steering each unit in the squad. Uses spatial partitioning optimization to only calculate separation vector with nearby units. BOIDS vectors are applied to units in a gradually, being applied to previous BOIDS vectors with a reduced magnitude to cause steering rather than flickering. | |
Static Public Attributes | |
| static unordered_map< BWAPI::Unit, pair< int, int >, unitHash > | leaderRadiusMap |
Static Private Member Functions | |
| static SeparationCell | unitToCell (BWAPI::Position pos) |
| Maps unit to a SeparationCell within the grid used for spatial partitioning. | |
| static VectorPos | getSeparationSteering (VectorPos unitPos, VectorPos neighborPos, VectorPos unitVelocity) |
| Calculates separation steering based on cross product between unit-neighbor vector and the unit's velocity vector. | |
| static VectorPos | getTerrainSteering (BWAPI::Unit unit, VectorPos unitPos, VectorPos leaderPos, VectorPos unitVelocity) |
| Checks ahead of unit and, if it finds a close enough terrain, returns vector pointing away from terrain. | |
| static bool | inLeaderRadius (VectorPos unitPos, VectorPos leaderPos, double leaderRadius) |
Static Private Attributes | |
| static unordered_map< BWAPI::Unit, int, unitHash > | terrainFrameMap |
| Maps unit to a frame counter, being reduced every frame. | |
| static unordered_map< BWAPI::Unit, VectorPos, unitHash > | terrainDirMap |
| Maps unit to a previously calculated terrain vector. | |
| static unordered_map< BWAPI::Unit, unordered_map< BWAPI::Unit, double, unitHash >, unitHash > | unitDistanceCache |
| Maps unit to an unordered_map of previous distance calculations for its surrounding units. | |
| static unordered_map< BWAPI::Unit, VectorPos, unitHash > | previousBOIDSMap |
| Maps unit to its previous BOIDS calculations to apply the current BOIDS vector gradually. | |
(DISCONTINUED)
Unfortunately, BOIDS could not be optimized enough to be run within tournament computation time rules. However, the algorithm is still a cool implementation of a flocking algorithm for unit movement, so it is being kept in the codebase for potential future use.
Uses flocking algorithm to maintain unit separation and formation while moving towards a position.
Units will adjust their position based on a leader vector, separation vector, and terrain avoidance vector.
Leader vector keeps units surrounding the squad leader, separation vector keeps units from crowding too tightly, and terrain avoidance vector keeps units away from terrain.
Normalization is done through VectorPos class
|
staticprivate |
Calculates separation steering based on cross product between unit-neighbor vector and the unit's velocity vector.
Uses cross product to determine whether to move left or right relative to the neighbouring unit.
This vector's magnitude is modified later in squadFlock() using SEPARATION_STRENGTH which is defined in BOIDS.h
| unitPos | Unit position in BWAPI::Position |
| neighborPos | Neighbor's position in BWAPI::Position |
| unitVelocity | Current velocity of unit in VectorPos |
Definition at line 273 of file BOIDS.cpp.
|
staticprivate |
Checks ahead of unit and, if it finds a close enough terrain, returns vector pointing away from terrain.
Uses unitVelocity to check all four corners of the unit. If, from these corners, the lookahead vectors find a terrain, the unit is going to collide with something soon.
Accumulates vectors pointing away from the terrain from each of the checked corners that found a terrain.
Final normalized vector used to steer unit away.
| unit | |
| unitPos | |
| leaderPos | |
| unitVelocity |
Definition at line 287 of file BOIDS.cpp.
|
static |
Main function of BOIDS flocking. Calculates leader, separation, and terrain avoidance vectors for steering each unit in the squad.
Uses spatial partitioning optimization to only calculate separation vector with nearby units.
BOIDS vectors are applied to units in a gradually, being applied to previous BOIDS vectors with a reduced magnitude to cause steering rather than flickering.
| squad |
Definition at line 14 of file BOIDS.cpp.
|
staticprivate |
Maps unit to a SeparationCell within the grid used for spatial partitioning.
Returns unit's SeparationCell on the spatial grid map (unitGrid) that stores unit counts on the game map's TilePositions
| pos | BWAPI::Position of the unit |
Definition at line 352 of file BOIDS.cpp.
|
static |
Maps unit to its previous BOIDS calculations to apply the current BOIDS vector gradually.
BOIDS forces/vectors are not applied in its entirety if a previous BOIDS vector was found.
This is to avoid doing sudden flickering movements due to new forces.
The current BOIDS direction is applied, with a reduced magnitude, to the previous BOIDS direction to "steer" the unit instead of drastically changing its direction.
Maps unit to a previously calculated terrain vector.
Tracks the vector the unit is currently travelling in to avoid terrain (if the unit had recently avoided any terrain)
If a unit is still avoiding terrain (terrainFrameMap[unit] > 0), then applies this direction to the boidsVector for the current frame.
|
staticprivate |
Maps unit to a frame counter, being reduced every frame.
To avoid constant checks for when units are near frames, the terrainFrameMap tracks the frames alotted to units for avoiding terrain.
If a unit's terrain frames are still greater than 0, the unit's terrain vector will not be calculated.
|
staticprivate |
Maps unit to an unordered_map of previous distance calculations for its surrounding units.
Since we're looping through units, the distance between two units will normally be checked twice. This distance measurement is expensive.
To optimize the distance calculation, this map tracks the distance between a unit and its surrounding units.
Once one unit calculates the distance between itself and other units, when the latter arrives in the loop the unit will check the map and find previously calculated distances.