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

An Agent represents the micromanagement state of one of our units. More...

#include <agent.h>

Public Member Functions

std::shared_ptr< UPCTuplemicroDelete ()
 Hand control of the unit over to the Agent for fighting. More...
 
std::shared_ptr< UPCTuplemicroFlee ()
 Hand control of the unit over to the Agent for fleeing. More...
 
void postCommand (tc::BW::UnitCommandType command)
 Issues a command to the Agent's unit by posting it to the Blackboard. More...
 
std::shared_ptr< UPCTupleattack (Position const &pos)
 Convenience method for issuing an attack-move UPC. More...
 
std::shared_ptr< UPCTupleattack (Unit *u)
 Convenience method for issuing an attack-unit UPC. More...
 
std::shared_ptr< UPCTuplemoveTo (Position pos, bool protect=true)
 Convenience method for issuing a move UPC. More...
 
std::shared_ptr< UPCTuplemoveTo (Vec2 pos, bool protect=true)
 Convenience method for issuing a move UPC. More...
 
std::shared_ptr< UPCTuplefilterMove (const movefilters::PositionFilters &pfs)
 Convenience method for issuing a move UPC using movefilters. More...
 
std::shared_ptr< UPCTuplesmartMove (const Position &tgt)
 Convenience method for issuing a threat-aware move UPC. More...
 
std::shared_ptr< UPCTuplesmartMove (Unit *tgt)
 Convenience method for issuing a threat-aware move UPC. More...
 
std::shared_ptr< UPCTupletryCastSpellOnUnit (const BuildType *spell, std::function< double(Unit *const)> scoring, double minimumScore)
 Attempt to cast a spell targeting a unit. More...
 
std::shared_ptr< UPCTupletryCastSpellOnArea (const BuildType *spell, double areaWidth, double areaHeight, std::function< double(Unit *const)> scoring, double minimumScore, std::function< Position(Position input)> positionTransform=[](auto p){return p;})
 Attempt to cast a spell targeting an area. More...
 

Public Attributes

SquadTask * task
 To what squad does this unit belong? More...
 
Unitunit
 What unit is this Agent controlling? More...
 
Statestate
 The current game state. More...
 
std::shared_ptr< BehaviorbehaviorDelete
 Behaviors to perform when receiving a Delete UPC. More...
 
std::shared_ptr< BehaviorbehaviorFlee
 Behaviors to perform when receiving a Flee UPC. More...
 
MicroAction currentAction
 What action has been selected for this unit by a Behavior? More...
 
std::vector< Unit * > legalTargets
 Who is this unit intended to fight? More...
 
Unittarget = nullptr
 Who has this unit decided to kill? More...
 
bool targetInRange = false
 Is the target in range right now? This accounts for latency and unit/target velocities. More...
 
bool prevTargetInRange = false
 
Unitattacking = nullptr
 Tracks the last target this unit was commanded to attack. More...
 
bool wantsToFight = false
 Has this unit joined the vanguard of its squad? Or is it on the way? More...
 
int lastMicroFrame = -1
 On what frame was this unit last micromanaged? More...
 
int lastTarget = -1
 On what frame did this unit last choose a target? More...
 
int lastMove = -1
 On what frame did this unit start moving? -1 when the unit is attacking, rather than moving. More...
 
int lastAttack = -1
 On what frame did this unit start attacking? -1 when the unit is not attacking. More...
 
Position lastMoveTo
 If we attempted to move the unit, the last position to which we attempted to move it. More...
 
Position lastPosition
 The unit's position last time we micromanaged it. More...
 
int stuckFrames = 0
 How many consecutive frames has this unit been inadvertently idle? More...
 
int mutaliskTurning = 0
 Is this unit a Mutalisk turning to face a Scourge? Used to apply the triangle method for kiting Scourge with Mutalisks. More...
 
Position formationPosition = kInvalidPosition
 SquadTask organizes its units into a formation for attacking. More...
 
int formationCounter = 0
 Used by SquadTask in calculating formations. More...
 

Static Public Attributes

static constexpr int unstickTriggerFrames = 9
 How many frames of being stuck before we attempt to un-stick a unit. More...
 

Protected Member Functions

void preMicro ()
 Prepare the unit for micro. More...
 

Detailed Description

An Agent represents the micromanagement state of one of our units.

Agents belong to a SquadTask, which invokes microFlee() or microDelete().

From there, the Agent, will forward control to a series of Behaviors, each of which is given the opportunity to do one of the following:

Member Function Documentation

std::shared_ptr< UPCTuple > cherrypi::Agent::attack ( Position const &  pos)

Convenience method for issuing an attack-move UPC.

std::shared_ptr< UPCTuple > cherrypi::Agent::attack ( Unit u)

Convenience method for issuing an attack-unit UPC.

std::shared_ptr< UPCTuple > cherrypi::Agent::filterMove ( const movefilters::PositionFilters pfs)

Convenience method for issuing a move UPC using movefilters.

std::shared_ptr< UPCTuple > cherrypi::Agent::microDelete ( )

Hand control of the unit over to the Agent for fighting.

std::shared_ptr< UPCTuple > cherrypi::Agent::microFlee ( )

Hand control of the unit over to the Agent for fleeing.

std::shared_ptr< UPCTuple > cherrypi::Agent::moveTo ( Position  pos,
bool  protect = true 
)

Convenience method for issuing a move UPC.

std::shared_ptr< UPCTuple > cherrypi::Agent::moveTo ( Vec2  pos,
bool  protect = true 
)

Convenience method for issuing a move UPC.

void cherrypi::Agent::postCommand ( tc::BW::UnitCommandType  command)

Issues a command to the Agent's unit by posting it to the Blackboard.

void cherrypi::Agent::preMicro ( )
protected

Prepare the unit for micro.

std::shared_ptr< UPCTuple > cherrypi::Agent::smartMove ( const Position tgt)

Convenience method for issuing a threat-aware move UPC.

std::shared_ptr< UPCTuple > cherrypi::Agent::smartMove ( Unit tgt)

Convenience method for issuing a threat-aware move UPC.

std::shared_ptr< UPCTuple > cherrypi::Agent::tryCastSpellOnArea ( const BuildType spell,
double  areaWidth,
double  areaHeight,
std::function< double(Unit *const)>  scoring,
double  minimumScore,
std::function< Position(Position input)>  positionTransform = [](auto p) { return p; } 
)

Attempt to cast a spell targeting an area.

Returns a UPC if an acceptable target was found; null otherwise.

std::shared_ptr< UPCTuple > cherrypi::Agent::tryCastSpellOnUnit ( const BuildType spell,
std::function< double(Unit *const)>  scoring,
double  minimumScore 
)

Attempt to cast a spell targeting a unit.

Returns a UPC if an acceptable target was found; null otherwise.

Member Data Documentation

Unit* cherrypi::Agent::attacking = nullptr

Tracks the last target this unit was commanded to attack.

std::shared_ptr<Behavior> cherrypi::Agent::behaviorDelete

Behaviors to perform when receiving a Delete UPC.

std::shared_ptr<Behavior> cherrypi::Agent::behaviorFlee

Behaviors to perform when receiving a Flee UPC.

MicroAction cherrypi::Agent::currentAction

What action has been selected for this unit by a Behavior?

int cherrypi::Agent::formationCounter = 0

Used by SquadTask in calculating formations.

Position cherrypi::Agent::formationPosition = kInvalidPosition

SquadTask organizes its units into a formation for attacking.

This is the Agent's assigned formation position, which it may use before fighting.

int cherrypi::Agent::lastAttack = -1

On what frame did this unit start attacking? -1 when the unit is not attacking.

int cherrypi::Agent::lastMicroFrame = -1

On what frame was this unit last micromanaged?

int cherrypi::Agent::lastMove = -1

On what frame did this unit start moving? -1 when the unit is attacking, rather than moving.

Position cherrypi::Agent::lastMoveTo

If we attempted to move the unit, the last position to which we attempted to move it.

Position cherrypi::Agent::lastPosition

The unit's position last time we micromanaged it.

int cherrypi::Agent::lastTarget = -1

On what frame did this unit last choose a target?

std::vector<Unit*> cherrypi::Agent::legalTargets

Who is this unit intended to fight?

int cherrypi::Agent::mutaliskTurning = 0

Is this unit a Mutalisk turning to face a Scourge? Used to apply the triangle method for kiting Scourge with Mutalisks.

bool cherrypi::Agent::prevTargetInRange = false
State* cherrypi::Agent::state

The current game state.

int cherrypi::Agent::stuckFrames = 0

How many consecutive frames has this unit been inadvertently idle?

Unit* cherrypi::Agent::target = nullptr

Who has this unit decided to kill?

bool cherrypi::Agent::targetInRange = false

Is the target in range right now? This accounts for latency and unit/target velocities.

SquadTask* cherrypi::Agent::task

To what squad does this unit belong?

Unit* cherrypi::Agent::unit

What unit is this Agent controlling?

constexpr int cherrypi::Agent::unstickTriggerFrames = 9
static

How many frames of being stuck before we attempt to un-stick a unit.

bool cherrypi::Agent::wantsToFight = false

Has this unit joined the vanguard of its squad? Or is it on the way?


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