TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cherrypi::BuilderControllerBase Class Reference

Base class for controllers used by BuilderModule. More...

#include <builderc.h>

Inherits cherrypi::Controller.

Inherited by cherrypi::BuilderController, and cherrypi::WorkerBuilderController.

Public Member Functions

 BuilderControllerBase (Module *module, BuildType const *type, std::unordered_map< Unit *, float > unitProbs, std::shared_ptr< BuilderControllerData > bcdata)
 
virtual ~BuilderControllerBase ()=default
 
virtual const char * getName () const override
 A name for this Controller, for debugging purposes. More...
 
float priority ()
 
void setPriority (float value)
 
BuildType const * type ()
 
- Public Member Functions inherited from cherrypi::Controller
 Controller (Module *module)
 
virtual ~Controller ()=default
 
void setUpcId (UpcId id)
 Set the UPC ID of the corresponding task. More...
 
- 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...
 

Protected Member Functions

virtual bool didSucceed () const override
 Implement this to return whether your custom Controller did succeed in its mission (if applicable) and can be disposed. More...
 
virtual bool didFail () const override
 Implement this to return whether your custom Controller did fail in its mission (if applicable) and can be disposed. More...
 
void grabUnit (State *state, Unit *unit)
 
void releaseUnit (State *state, Unit *unit)
 
bool findBuilder (State *state, Position const &pos=Position())
 
auto defaultUnitBuilderScore (State *state)
 Returns scoring function for selecting a unit to build another (non-building) unit. More...
 
auto larvaBuilderScore (State *state, bool preferSaturation)
 Returns scoring function for selecting a unit to build a Larva-based unit. More...
 
auto hatcheryTechBuilderScore (State *state)
 Returns scoring function for selecting a unit to morph a hatchery or lair. More...
 
bool cancelled (State *state) const
 
- 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

BuildType const * type_
 
Unitbuilder_ = nullptr
 
std::unordered_map< Unit *, float > unitProbs_
 
std::shared_ptr< BuilderControllerDatabcdata_
 
bool succeeded_ = false
 
bool failed_ = false
 
float priority_
 
- Protected Attributes inherited from cherrypi::Controller
UpcId upcId_
 
- Protected Attributes inherited from cherrypi::ControllerBase
Modulemodule_
 
std::unordered_map< Unit *, UpcIdunits_
 
std::unordered_map< Unit *, std::pair< UpcId, std::shared_ptr< UPCTuple > > > upcs_
 

Detailed Description

Base class for controllers used by BuilderModule.

Builder-related tasks will select a unit when they are ready for production or construction and not upon creation. Hence, relevant controllers will advertise the units they're using via currentUnits(), and the module that uses them will need to make sure that proper player-wide allocation is done after calling step().

Constructor & Destructor Documentation

cherrypi::BuilderControllerBase::BuilderControllerBase ( Module module,
BuildType const *  type,
std::unordered_map< Unit *, float >  unitProbs,
std::shared_ptr< BuilderControllerData bcdata 
)
virtual cherrypi::BuilderControllerBase::~BuilderControllerBase ( )
virtualdefault

Member Function Documentation

bool cherrypi::BuilderControllerBase::cancelled ( State state) const
protected
auto cherrypi::BuilderControllerBase::defaultUnitBuilderScore ( State state)
protected

Returns scoring function for selecting a unit to build another (non-building) unit.

virtual bool cherrypi::BuilderControllerBase::didFail ( ) const
inlineoverrideprotectedvirtual

Implement this to return whether your custom Controller did fail in its mission (if applicable) and can be disposed.

By default, a Controller fails if it does not control any units.

Reimplemented from cherrypi::Controller.

virtual bool cherrypi::BuilderControllerBase::didSucceed ( ) const
inlineoverrideprotectedvirtual

Implement this to return whether your custom Controller did succeed in its mission (if applicable) and can be disposed.

By default, this returns false.

Reimplemented from cherrypi::Controller.

bool cherrypi::BuilderControllerBase::findBuilder ( State state,
Position const &  pos = Position() 
)
protected
virtual const char* cherrypi::BuilderControllerBase::getName ( ) const
inlineoverridevirtual

A name for this Controller, for debugging purposes.

Reimplemented from cherrypi::ControllerBase.

Reimplemented in cherrypi::WorkerBuilderController.

void cherrypi::BuilderControllerBase::grabUnit ( State state,
Unit unit 
)
protected
auto cherrypi::BuilderControllerBase::hatcheryTechBuilderScore ( State state)
protected

Returns scoring function for selecting a unit to morph a hatchery or lair.

auto cherrypi::BuilderControllerBase::larvaBuilderScore ( State state,
bool  preferSaturation 
)
protected

Returns scoring function for selecting a unit to build a Larva-based unit.

float cherrypi::BuilderControllerBase::priority ( )
inline
void cherrypi::BuilderControllerBase::releaseUnit ( State state,
Unit unit 
)
protected
void cherrypi::BuilderControllerBase::setPriority ( float  value)
inline
BuildType const* cherrypi::BuilderControllerBase::type ( )
inline

Member Data Documentation

std::shared_ptr<BuilderControllerData> cherrypi::BuilderControllerBase::bcdata_
protected
Unit* cherrypi::BuilderControllerBase::builder_ = nullptr
protected
bool cherrypi::BuilderControllerBase::failed_ = false
protected
float cherrypi::BuilderControllerBase::priority_
protected
bool cherrypi::BuilderControllerBase::succeeded_ = false
protected
BuildType const* cherrypi::BuilderControllerBase::type_
protected
std::unordered_map<Unit*, float> cherrypi::BuilderControllerBase::unitProbs_
protected

The documentation for this class was generated from the following files: