TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
|
Base class for controllers. More...
#include <controller.h>
Inherited by cherrypi::Controller, and cherrypi::SharedController.
Public Member Functions | |
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... | |
Protected Member Functions | |
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 | |
Module * | module_ |
std::unordered_map< Unit *, UpcId > | units_ |
std::unordered_map< Unit *, std::pair< UpcId, std::shared_ptr< UPCTuple > > > | upcs_ |
Base class for controllers.
A Controller is a mix between a Task and a Module: it has a sense of unit ownership and contains state similar to Task, and has a step() function which is used to post UPCs to Blackboard similar to Module. It is tailored to control of individual units: units can be added or removed, and per-unit UPC posting is made easy.
For using a controller, Module and Task objects still required. Module create controller instances and call step(). Tasks take care of player-wide unit allocation via Blackboard and provide source UPCs for each unit being controller.
See Controller and SharedController for usage exampels of two common controller patterns.
cherrypi::ControllerBase::ControllerBase | ( | Module * | module | ) |
|
virtualdefault |
Add a unit to this controller.
This is usually called whenever a new Task for a controller is being cretaed. Re-implement this function if you need to update internal data structures when gaining control of units but make sure to also call the base class method.
Reimplemented in cherrypi::GathererController.
|
inlineprotected |
Schedules an action (as a UPC) for the given unit which will be posted after doStep().
|
inlinevirtual |
A name for this Controller, for debugging purposes.
Reimplemented in cherrypi::WorkerBuilderController, cherrypi::BuilderControllerBase, and cherrypi::GathererController.
Checks if the controller is controlling the given unit via the given UPC ID.
Tasks are required to call this function before calling removeUnit() when removing units from controllers.
Decide whether to keep a unit.
By default, this returns false for dead and non-allied units.
Reimplemented in cherrypi::GathererController.
|
protected |
Posts scheduled UPCs to the Blackboard.
UPCs can be scheduled by addUpc().
Remove a unit from this controller.
This is usually called from Task::update() to remove units that were assigned to other Tasks, or for which keepUnit() returns false. Re-implement this function if you need to update internal data structures when gaining control of units but make sure to also call the base class method.
Reimplemented in cherrypi::BuilderController, cherrypi::WorkerBuilderController, and cherrypi::GathererController.
|
virtual |
Advance controller state and produce UPCs.
This is intended to be called from Module::step() of the instantiating module. The default implementation does nothing.
Reimplemented in cherrypi::BuilderController, cherrypi::WorkerBuilderController, and cherrypi::GathererController.
|
protected |
|
protected |