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

The Tactics module decides where on the map to allocate combat units. More...

#include <tactics.h>

Inherits cherrypi::Module.

Inherited by cherrypi::TacticsAlwaysFightModule.

Public Member Functions

virtual void step (State *s) override
 
virtual void onGameEnd (State *s) override
 
- Public Member Functions inherited from cherrypi::Module
virtual ~Module ()=default
 
virtual void setPlayer (BasePlayer *p)
 
void setName (std::string name)
 
std::string name ()
 
virtual void onGameStart (State *s)
 

Protected Member Functions

UpcId findSourceUpc (State *s)
 
virtual void process (State *state, int srcUpcId)
 
void formGroups (State *state, TacticsState &tstate, std::vector< Unit * > &leftoverWorkers, std::unordered_set< Unit * > &wasInAGroup)
 Create groups based on distance rules, useful for the scouting/worker/search and destroy functionality. More...
 
void distributeLeftoverWorkers (std::unordered_set< Unit * > &unitSet, std::vector< Unit * > &leftoverWorkers, std::unordered_set< Unit * > &wasInAGroup)
 Return unused workers, doesn't rely on group creation, just on existance of leftoverWorkers which specifies the workers and wasInAGroup which specifies which will automatically be reassigned based on attachement to a previously existing task. More...
 
void processNonFightFleeGroup (State *state, TacticsState &tstate, TacticsGroup &g, std::vector< Unit * > &leftoverWorkers, std::unordered_set< Unit * > &wasInAGroup)
 Takes the scouting & search and destroy groups created in formGroups and issues the commands, also returns leftoverWorkers. More...
 
void moveUnit (State *state, UpcId srcUpcId, Unit *u, Position target)
 Creates a move upc for unit with given target. More...
 
std::pair< double, double > distributeFightFlee (State *state, TacticsState &tstate, TacticsGroup &g, std::vector< Unit * > &fightUnits, std::vector< Unit * > &fleeUnits)
 Uses combat sim + rules to put each unit into a fight or flee vector. More...
 
void processOrders (State *state, TacticsGroup &g, int srcUpcId, double deleteScore, double moveScore, std::vector< Unit * > &fightUnits, std::vector< Unit * > &fleeUnits, std::vector< Unit * > &leftoverWorkers, std::unordered_set< Unit * > &wasInAGroup)
 Takes a group and the fight/flee assignments and issues commands. More...
 
virtual bool alwaysFight ()
 
- Protected Member Functions inherited from cherrypi::Module
 Module ()
 

Protected Attributes

FrameNum lastProcess_ = 0
 
std::vector< uint8_t > inBaseArea_
 
FrameNum lastUpdateInBaseArea_ = 0
 
std::vector< uint16_t > fleeScore_
 
FrameNum lastUpdateFleeScore_ = 0
 
std::unordered_map< Unit *, std::pair< int, Position > > searchAndDestroyTarget_
 
std::unordered_map< Unit *, std::pair< int, Position > > scoutTarget_
 
std::ranlux24 rngEngine_ {42}
 
std::unordered_map< Unit *, int > lastTargetInRange_
 
std::unordered_map< Unit *, int > lastMove_
 
- Protected Attributes inherited from cherrypi::Module
BasePlayerplayer_
 
std::string name_
 

Additional Inherited Members

- Static Public Member Functions inherited from cherrypi::Module
template<typename T , typename... Args>
static std::shared_ptr< T > make (Args &&...args)
 
static std::shared_ptr< Modulemake (std::string const &typeName)
 
static std::string makeName (std::type_index const &type)
 

Detailed Description

The Tactics module decides where on the map to allocate combat units.

Finally, outputs a UPC for each group of units indicating where they should go or what they should fight.

Member Function Documentation

virtual bool cherrypi::TacticsModule::alwaysFight ( )
inlineprotectedvirtual
std::pair< double, double > cherrypi::TacticsModule::distributeFightFlee ( State state,
TacticsState tstate,
TacticsGroup g,
std::vector< Unit * > &  fightUnits,
std::vector< Unit * > &  fleeUnits 
)
protected

Uses combat sim + rules to put each unit into a fight or flee vector.

void cherrypi::TacticsModule::distributeLeftoverWorkers ( std::unordered_set< Unit * > &  unitSet,
std::vector< Unit * > &  leftoverWorkers,
std::unordered_set< Unit * > &  wasInAGroup 
)
protected

Return unused workers, doesn't rely on group creation, just on existance of leftoverWorkers which specifies the workers and wasInAGroup which specifies which will automatically be reassigned based on attachement to a previously existing task.

UpcId cherrypi::TacticsModule::findSourceUpc ( State s)
protected
void cherrypi::TacticsModule::formGroups ( State state,
TacticsState tstate,
std::vector< Unit * > &  leftoverWorkers,
std::unordered_set< Unit * > &  wasInAGroup 
)
protected

Create groups based on distance rules, useful for the scouting/worker/search and destroy functionality.

void cherrypi::TacticsModule::moveUnit ( State state,
UpcId  srcUpcId,
Unit u,
Position  target 
)
protected

Creates a move upc for unit with given target.

void cherrypi::TacticsModule::onGameEnd ( State s)
overridevirtual

Reimplemented from cherrypi::Module.

void cherrypi::TacticsModule::process ( State state,
int  srcUpcId 
)
protectedvirtual
void cherrypi::TacticsModule::processNonFightFleeGroup ( State state,
TacticsState tstate,
TacticsGroup g,
std::vector< Unit * > &  leftoverWorkers,
std::unordered_set< Unit * > &  wasInAGroup 
)
protected

Takes the scouting & search and destroy groups created in formGroups and issues the commands, also returns leftoverWorkers.

void cherrypi::TacticsModule::processOrders ( State state,
TacticsGroup g,
int  srcUpcId,
double  deleteScore,
double  moveScore,
std::vector< Unit * > &  fightUnits,
std::vector< Unit * > &  fleeUnits,
std::vector< Unit * > &  leftoverWorkers,
std::unordered_set< Unit * > &  wasInAGroup 
)
protected

Takes a group and the fight/flee assignments and issues commands.

void cherrypi::TacticsModule::step ( State s)
overridevirtual

Reimplemented from cherrypi::Module.

Member Data Documentation

std::vector<uint16_t> cherrypi::TacticsModule::fleeScore_
protected
Initial value:
std::vector<uint8_t> cherrypi::TacticsModule::inBaseArea_
protected
Initial value:
std::unordered_map<Unit*, int> cherrypi::TacticsModule::lastMove_
protected
FrameNum cherrypi::TacticsModule::lastProcess_ = 0
protected
std::unordered_map<Unit*, int> cherrypi::TacticsModule::lastTargetInRange_
protected
FrameNum cherrypi::TacticsModule::lastUpdateFleeScore_ = 0
protected
FrameNum cherrypi::TacticsModule::lastUpdateInBaseArea_ = 0
protected
std::ranlux24 cherrypi::TacticsModule::rngEngine_ {42}
protected
std::unordered_map<Unit*, std::pair<int, Position> > cherrypi::TacticsModule::scoutTarget_
protected
std::unordered_map<Unit*, std::pair<int, Position> > cherrypi::TacticsModule::searchAndDestroyTarget_
protected

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