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

AutoBuildTasks are "build orders" in the colloquial sense. More...

#include <autobuild.h>

Inherits cherrypi::MultiProxyTask.

Inherited by cherrypi::ABBOBase, and cherrypi::DefaultAutoBuildTask.

Public Member Functions

void postBlackboardKey (std::string const &key, Blackboard::Data const &data)
 
bool cancelGas ()
 
 AutoBuildTask (int upcId, State *state, Module *module)
 
virtual ~AutoBuildTask () override
 
virtual void update (State *state) override
 
void evaluate (State *state, Module *module)
 
void simEvaluateFor (autobuild::BuildState &st, FrameNum frames)
 
virtual void preBuild (autobuild::BuildState &st)
 One of the three steps of processing a build order. More...
 
virtual void buildStep (autobuild::BuildState &st)
 The meat of a build order lives in buildStep(). More...
 
virtual void postBuild (autobuild::BuildState &st)
 The final step of processing a build order. More...
 
void build (const BuildType *type, Position pos, std::function< void()> builtCallback)
 Builds a building at a specific position. More...
 
void build (const BuildType *type, std::function< void()> builtCallback)
 Builds a unit/building, upgrade, or technology. More...
 
void build (const BuildType *type, Position pos)
 Builds a building at a specific position. More...
 
void build (const BuildType *type)
 Builds a unit/building, upgrade, or technology. More...
 
bool buildN (const BuildType *type, int n)
 Builds up to N of a unit/building. More...
 
bool buildN (const BuildType *type, int n, int simultaneous)
 Builds up to N of a unit/building, with an optional limit on how many to build consecutively. More...
 
bool buildN (const BuildType *type, int n, Position positionIfWeBuildMore)
 Builds up to N of a building, specifying a position for the next new building. More...
 
bool upgrade (const BuildType *type)
 Researches an Upgrade or Tech Enqueues any required but missing prerequisites (like adding a Lair if you request Lurker Aspect). More...
 
autobuild::BuildStatelastEvaluateCurrentState ()
 
autobuild::BuildStatelastEvaluateTargetState ()
 
- Public Member Functions inherited from cherrypi::MultiProxyTask
 MultiProxyTask (std::vector< UpcId > targetUpcIds, UpcId upcId)
 
virtual ~MultiProxyTask ()=default
 
void setPolicyForStatus (TaskStatus status, ProxyPolicy policy)
 
virtual void cancel (State *state) override
 
virtual std::unordered_set< Unit * > const & proxiedUnits () const override
 A set of units occupied performing this task. More...
 
std::vector< std::shared_ptr< Task > > targets () const
 
- Public Member Functions inherited from cherrypi::Task
 Task (UpcId upcId, std::unordered_set< Unit * > units={})
 
virtual ~Task ()
 
TaskStatus status () const
 
void setStatus (TaskStatus status)
 
bool finished () const
 
UpcId upcId () const
 UPC id in Blackboard that caused this Task to be spawned. More...
 
std::unordered_set< Unit * > const & units () const
 A set of units occupied performing this task. More...
 
void removeUnit (Unit *unit)
 
virtual const char * getName () const
 A name for this task, for debugging purposes. More...
 

Public Attributes

int lastEvaluate = 0
 
autobuild::BuildState initialBuildState
 
autobuild::BuildState currentBuildState
 
Statestate_ = nullptr
 
bool isSimulation = false
 
std::unordered_map< UpcId, std::tuple< autobuild::BuildEntry, float > > scheduledUpcs
 Each of these UPCs is being proxied by this task. More...
 
std::function< bool(autobuild::BuildState &)> queue
 

Protected Member Functions

virtual void draw (State *state)
 Draws any debugging information to the screen. More...
 
- Protected Member Functions inherited from cherrypi::MultiProxyTask
bool matchStatus (TaskStatus status)
 
- Protected Member Functions inherited from cherrypi::Task
std::unordered_set< Unit * > & units ()
 
virtual void removeDeadOrReassignedUnits (State *state)
 Remove units that have been assigned to another task and units that have died. More...
 

Additional Inherited Members

- Protected Attributes inherited from cherrypi::MultiProxyTask
std::vector< UpcIdtargetUpcIds_
 
std::vector< std::shared_ptr< Task > > targets_
 
std::unordered_set< Unit * > proxiedUnits_
 
std::map< TaskStatus, ProxyPolicypolicy_
 
TaskStatus defaultTargetStatus_ = TaskStatus::Unknown
 

Detailed Description

AutoBuildTasks are "build orders" in the colloquial sense.

You can subclass AutoBuildTask to design a build order.

In practice, build orders are usually based on a subclass of AutoBuildTask called ABBOBase (AutoBuild Build Order Base) which provides handy convenience methods.

Constructor & Destructor Documentation

cherrypi::AutoBuildTask::AutoBuildTask ( int  upcId,
State state,
Module module 
)
inline
virtual cherrypi::AutoBuildTask::~AutoBuildTask ( )
inlineoverridevirtual

Member Function Documentation

void cherrypi::AutoBuildTask::build ( const BuildType type,
Position  pos,
std::function< void()>  builtCallback 
)

Builds a building at a specific position.

Invokes a callback when we attempt to begin construction. Enqueues any required but missing prerequisites (like adding a Lair if you request a Spire).

void cherrypi::AutoBuildTask::build ( const BuildType type,
std::function< void()>  builtCallback 
)

Builds a unit/building, upgrade, or technology.

Invokes a callback when we attempt to begin construction. Enqueues any required but missing prerequisites (like adding a Spire if you request a Mutalisk).

void cherrypi::AutoBuildTask::build ( const BuildType type,
Position  pos 
)

Builds a building at a specific position.

Enqueues any required but missing prerequisites (like adding a Lair if you request a Spire).

void cherrypi::AutoBuildTask::build ( const BuildType type)

Builds a unit/building, upgrade, or technology.

Enqueues any required but missing prerequisites (like adding a Lair if you request a Spire).

bool cherrypi::AutoBuildTask::buildN ( const BuildType type,
int  n 
)

Builds up to N of a unit/building.

Enqueues any required but missing prerequisites like adding a Lair if you request a Spire).

bool cherrypi::AutoBuildTask::buildN ( const BuildType type,
int  n,
int  simultaneous 
)

Builds up to N of a unit/building, with an optional limit on how many to build consecutively.

Enqueues any required but missing prerequisites like adding a Lair if you request a Spire).

bool cherrypi::AutoBuildTask::buildN ( const BuildType type,
int  n,
Position  positionIfWeBuildMore 
)

Builds up to N of a building, specifying a position for the next new building.

Enqueues any required but missing prerequisites (like adding a Lair if you request a Spire).

virtual void cherrypi::AutoBuildTask::buildStep ( autobuild::BuildState st)
inlinevirtual

The meat of a build order lives in buildStep().

This is where you decide what to build, and in what order.

Here's how buildStep() works:

After preBuild(), AutoBuildTask invokes buildStep() with a BuildState reflecting the current state of the game. That includes the amount of minerals, gas, and supply you have. It also has an empty queue of things to build.

In your implementation of buildStep(), you can specify everything you want to build, via methods like build() and upgrade(). These methods add your requested items to the queue in BuildState.

However, only the last request which would modify the queue actually modifies the BuildState. This request goes to the end of the build queue. The BuildState updates to reflect the request: minerals/gas is spent, supply is updated, etc.

Then, if anything was changed, buildStep() is invoked again with the new BuildState. The last request from the previous build is now reflected in the new BuildState. For example, if you have no Spawning Pool, and the last request was buildN(Spawning_Pool, 1), the BuildState will now contain the Spawning Pool you requested.

This continues until either the queue has reached a certain length (several minutes into the future) or all requests are enqueued.

Reimplemented in cherrypi::DefaultAutoBuildTask, and cherrypi::ABBOBase.

bool cherrypi::AutoBuildTask::cancelGas ( )
void cherrypi::AutoBuildTask::draw ( State state)
protectedvirtual

Draws any debugging information to the screen.

Reimplemented in cherrypi::ABBOBase.

void cherrypi::AutoBuildTask::evaluate ( State state,
Module module 
)
autobuild::BuildState& cherrypi::AutoBuildTask::lastEvaluateCurrentState ( )
inline
autobuild::BuildState& cherrypi::AutoBuildTask::lastEvaluateTargetState ( )
inline
void cherrypi::AutoBuildTask::postBlackboardKey ( std::string const &  key,
Blackboard::Data const &  data 
)
virtual void cherrypi::AutoBuildTask::postBuild ( autobuild::BuildState st)
inlinevirtual

The final step of processing a build order.

postBuild() is invoked after the last invocation of buildStep().

Reimplemented in cherrypi::ABBOBase.

virtual void cherrypi::AutoBuildTask::preBuild ( autobuild::BuildState st)
inlinevirtual

One of the three steps of processing a build order.

preBuild() is invoked once before stepping through the build order.

Because it's invoked exactly once (unlike buildStep() which is invoked repeatedly) preBuild is a good place for making decisions that don't directly involve the build queue, like deciding whether to attack or deciding whether to mine gas.

Reimplemented in cherrypi::ABBOBase.

void cherrypi::AutoBuildTask::simEvaluateFor ( autobuild::BuildState st,
FrameNum  frames 
)
void cherrypi::AutoBuildTask::update ( State state)
overridevirtual

Reimplemented from cherrypi::MultiProxyTask.

bool cherrypi::AutoBuildTask::upgrade ( const BuildType type)

Researches an Upgrade or Tech Enqueues any required but missing prerequisites (like adding a Lair if you request Lurker Aspect).

Member Data Documentation

autobuild::BuildState cherrypi::AutoBuildTask::currentBuildState
autobuild::BuildState cherrypi::AutoBuildTask::initialBuildState
bool cherrypi::AutoBuildTask::isSimulation = false
int cherrypi::AutoBuildTask::lastEvaluate = 0
std::function<bool(autobuild::BuildState&)> cherrypi::AutoBuildTask::queue
std::unordered_map<UpcId, std::tuple<autobuild::BuildEntry, float> > cherrypi::AutoBuildTask::scheduledUpcs

Each of these UPCs is being proxied by this task.

State* cherrypi::AutoBuildTask::state_ = nullptr

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