TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
|
Base class for Controllers shared between multiple tasks. More...
#include <controller.h>
Inherits cherrypi::ControllerBase.
Inherited by cherrypi::GathererController.
Public Member Functions | |
virtual | ~SharedController ()=default |
Public Member Functions inherited from cherrypi::ControllerBase | |
ControllerBase (Module *module) | |
virtual | ~ControllerBase ()=default |
virtual void | addUnit (State *state, Unit *unit, UpcId id) |
Add a unit to this controller. More... | |
virtual void | removeUnit (State *state, Unit *unit, UpcId id) |
Remove a unit from this controller. More... | |
virtual bool | keepUnit (State *state, Unit *unit) const |
Decide whether to keep a unit. More... | |
virtual void | step (State *state) |
Advance controller state and produce UPCs. More... | |
bool | isControllingUnitWith (Unit *unit, UpcId id) const |
Checks if the controller is controlling the given unit via the given UPC ID. More... | |
virtual const char * | getName () const |
A name for this Controller, for debugging purposes. More... | |
Static Public Member Functions | |
template<typename T > | |
static std::shared_ptr< T > | globalInstance (State *state, Module *module, std::string name=std::string()) |
Retrieves the global instance of a shared controller. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from cherrypi::ControllerBase | |
void | postUpcs (State *state) |
Posts scheduled UPCs to the Blackboard. More... | |
template<typename... Args> | |
void | addUpc (Unit *unit, Args &&...args) |
Schedules an action (as a UPC) for the given unit which will be posted after doStep(). More... | |
Protected Attributes inherited from cherrypi::ControllerBase | |
Module * | module_ |
std::unordered_map< Unit *, UpcId > | units_ |
std::unordered_map< Unit *, std::pair< UpcId, std::shared_ptr< UPCTuple > > > | upcs_ |
Base class for Controllers shared between multiple tasks.
A common pattern is the control of multiple units in a centralized fashion. Since unit allocation is globally managed via Task objects which have a 1:1 relation to their respective UPCs, this requires handling multiple Task objects.
With SharedController and SharedControllerTask, this pattern can be implemented quite easily by inheriting from SharedController. Typically, the resulting code in Module::step() will look similar to this:
|
virtualdefault |
|
inlinestatic |
Retrieves the global instance of a shared controller.
Shared controllers can be stored in the Blackboard. This function will create the requested controller object if necessary (the Blackboard key is "controller_<module name>/<controller name>"