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

The main bot object. More...

#include <baseplayer.h>

Inherited by cherrypi::MicroPlayer, and cherrypi::Player.

Public Member Functions

 BasePlayer (std::shared_ptr< tc::Client > client)
 
virtual ~BasePlayer ()
 
 BasePlayer (const BasePlayer &)=delete
 
BasePlayeroperator= (const BasePlayer &)=delete
 
Statestate ()
 
std::shared_ptr< ModulegetTopModule () const
 
void addModule (std::shared_ptr< Module > module)
 
void addModules (std::vector< std::shared_ptr< Module >> const &modules)
 
template<typename T >
std::shared_ptr< T > findModule ()
 
void queueCmds (const std::vector< tc::Client::Command > &cmds)
 Add some commands to the queue, they will be executed on next step() More...
 
void setWarnIfSlow (bool warn)
 Log a warning if step() exceeds a maximum duration. More...
 
void setRealtimeFactor (float factor)
 Delay step() to make the game run in approx. factor*fastest speed. More...
 
void setCheckConsistency (bool check)
 Set whether to perform consistency checks during the game. More...
 
void setCollectTimers (bool collect)
 Set whether to gather timing statistics during the game. More...
 
void setLogFailedCommands (bool log)
 Set whether to log failed commands (via VLOG(0)). More...
 
void setDraw (bool draw)
 Set whether to post drawing commands (if any are posted). More...
 
virtual void stepModule (std::shared_ptr< Module > module)
 
void stepModules ()
 
void step ()
 
size_t steps () const
 
virtual void init ()
 
void leave ()
 
void dumpTraceAlongReplay (std::string const &replayFile)
 

Protected Types

using commandStartEndFrame = std::pair< tc::BW::UnitCommandType, std::pair< FrameNum, FrameNum >>
 

Protected Member Functions

virtual void preStep ()
 
virtual void postStep ()
 
void logFailedCommands ()
 
ClientCommands doStep ()
 Do the actual per-step work. More...
 

Protected Attributes

std::shared_ptr< tc::Clientclient_
 
int frameskip_ = 1
 
int combineFrames_ = 3
 
bool warnIfSlow_ = false
 
bool nonBlocking_ = false
 
bool checkConsistency_ = false
 
bool collectTimers_ = false
 
bool logFailedCommands_ = false
 
int lastFrameStepped_ = 0
 
int framesDropped_ = 0
 
float realtimeFactor_ = -1.0f
 
std::vector< std::shared_ptr< Module > > modules_
 
Statestate_
 
std::shared_ptr< Moduletop_
 
std::unordered_map< std::shared_ptr< Module >, DurationmoduleTimeSpent_
 
std::unordered_map< std::shared_ptr< Module >, DurationmoduleTimeSpentAgg_
 
Duration stateUpdateTimeSpent_
 
Duration stateUpdateTimeSpentAgg_
 
size_t steps_ = 0
 
bool initialized_ = false
 
bool firstStepDone_ = false
 
hires_clock::time_point lastStep_
 
bool draw_ = true
 
std::vector< tc::Client::Command > pendingCmds_
 

Static Protected Attributes

static decltype(std::chrono::milliseconds(50)) const kMaxStepDuration
 
static decltype(std::chrono::seconds(9)) const kMaxInitialStepDuration
 
static decltype(std::chrono::milliseconds(42)) const kStepDurationAtFastest
 

Detailed Description

The main bot object.

This class is used to play StarCraft Broodwar (TM) via the TorchCraft bridge. The behavior and actions of the player are determined by a user-supplied list of bot modules.

Member Typedef Documentation

using cherrypi::BasePlayer::commandStartEndFrame = std::pair<tc::BW::UnitCommandType, std::pair<FrameNum, FrameNum>>
protected

Constructor & Destructor Documentation

cherrypi::BasePlayer::BasePlayer ( std::shared_ptr< tc::Client client)
cherrypi::BasePlayer::~BasePlayer ( )
virtual
cherrypi::BasePlayer::BasePlayer ( const BasePlayer )
delete

Member Function Documentation

void cherrypi::BasePlayer::addModule ( std::shared_ptr< Module module)
void cherrypi::BasePlayer::addModules ( std::vector< std::shared_ptr< Module >> const &  modules)
BasePlayer::ClientCommands cherrypi::BasePlayer::doStep ( )
protected

Do the actual per-step work.

void cherrypi::BasePlayer::dumpTraceAlongReplay ( std::string const &  replayFile)
template<typename T >
std::shared_ptr<T> cherrypi::BasePlayer::findModule ( )
inline
std::shared_ptr< Module > cherrypi::BasePlayer::getTopModule ( ) const
virtual void cherrypi::BasePlayer::init ( )
inlinevirtual

Reimplemented in cherrypi::Player.

void cherrypi::BasePlayer::leave ( )
void cherrypi::BasePlayer::logFailedCommands ( )
protected
BasePlayer& cherrypi::BasePlayer::operator= ( const BasePlayer )
delete
void cherrypi::BasePlayer::postStep ( )
protectedvirtual
void cherrypi::BasePlayer::preStep ( )
protectedvirtual
void cherrypi::BasePlayer::queueCmds ( const std::vector< tc::Client::Command > &  cmds)

Add some commands to the queue, they will be executed on next step()

void cherrypi::BasePlayer::setCheckConsistency ( bool  check)

Set whether to perform consistency checks during the game.

void cherrypi::BasePlayer::setCollectTimers ( bool  collect)

Set whether to gather timing statistics during the game.

void cherrypi::BasePlayer::setDraw ( bool  draw)

Set whether to post drawing commands (if any are posted).

Defaults to true.

void cherrypi::BasePlayer::setLogFailedCommands ( bool  log)

Set whether to log failed commands (via VLOG(0)).

void cherrypi::BasePlayer::setRealtimeFactor ( float  factor)

Delay step() to make the game run in approx. factor*fastest speed.

void cherrypi::BasePlayer::setWarnIfSlow ( bool  warn)

Log a warning if step() exceeds a maximum duration.

Defaults to false.

State* cherrypi::BasePlayer::state ( )
inline
void cherrypi::BasePlayer::step ( )
void cherrypi::BasePlayer::stepModule ( std::shared_ptr< Module module)
virtual
void cherrypi::BasePlayer::stepModules ( )
size_t cherrypi::BasePlayer::steps ( ) const
inline

Member Data Documentation

bool cherrypi::BasePlayer::checkConsistency_ = false
protected
std::shared_ptr<tc::Client> cherrypi::BasePlayer::client_
protected
bool cherrypi::BasePlayer::collectTimers_ = false
protected
int cherrypi::BasePlayer::combineFrames_ = 3
protected
bool cherrypi::BasePlayer::draw_ = true
protected
bool cherrypi::BasePlayer::firstStepDone_ = false
protected
int cherrypi::BasePlayer::framesDropped_ = 0
protected
int cherrypi::BasePlayer::frameskip_ = 1
protected
bool cherrypi::BasePlayer::initialized_ = false
protected
const std::chrono::seconds cherrypi::BasePlayer::kMaxInitialStepDuration
staticprotected
Initial value:
=
std::chrono::seconds(9)
const std::chrono::milliseconds cherrypi::BasePlayer::kMaxStepDuration
staticprotected
Initial value:
=
std::chrono::milliseconds(40)
const std::chrono::milliseconds cherrypi::BasePlayer::kStepDurationAtFastest
staticprotected
Initial value:
=
std::chrono::milliseconds(42)
int cherrypi::BasePlayer::lastFrameStepped_ = 0
protected
hires_clock::time_point cherrypi::BasePlayer::lastStep_
protected
bool cherrypi::BasePlayer::logFailedCommands_ = false
protected
std::vector<std::shared_ptr<Module> > cherrypi::BasePlayer::modules_
protected
std::unordered_map<std::shared_ptr<Module>, Duration> cherrypi::BasePlayer::moduleTimeSpent_
protected
std::unordered_map<std::shared_ptr<Module>, Duration> cherrypi::BasePlayer::moduleTimeSpentAgg_
protected
bool cherrypi::BasePlayer::nonBlocking_ = false
protected
std::vector<tc::Client::Command> cherrypi::BasePlayer::pendingCmds_
protected
float cherrypi::BasePlayer::realtimeFactor_ = -1.0f
protected
State* cherrypi::BasePlayer::state_
protected
Duration cherrypi::BasePlayer::stateUpdateTimeSpent_
protected
Duration cherrypi::BasePlayer::stateUpdateTimeSpentAgg_
protected
size_t cherrypi::BasePlayer::steps_ = 0
protected
std::shared_ptr<Module> cherrypi::BasePlayer::top_
protected
bool cherrypi::BasePlayer::warnIfSlow_ = false
protected

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