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

The main bot object for training scenarios. More...

#include <microplayer.h>

Inherits cherrypi::BasePlayer.

Public Member Functions

 MicroPlayer (std::shared_ptr< tc::Client > client)
 
 MicroPlayer (const MicroPlayer &)=delete
 
MicroPlayeroperator= (const MicroPlayer &)=delete
 
void onGameStart ()
 
void onGameEnd ()
 
- Public Member Functions inherited from cherrypi::BasePlayer
 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 Attributes

bool gameStarted_ = false
 
- Protected Attributes inherited from cherrypi::BasePlayer
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_
 

Additional Inherited Members

- Protected Types inherited from cherrypi::BasePlayer
using commandStartEndFrame = std::pair< tc::BW::UnitCommandType, std::pair< FrameNum, FrameNum >>
 
- Protected Member Functions inherited from cherrypi::BasePlayer
virtual void preStep ()
 
virtual void postStep ()
 
void logFailedCommands ()
 
ClientCommands doStep ()
 Do the actual per-step work. More...
 
- Static Protected Attributes inherited from cherrypi::BasePlayer
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 for training scenarios.

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.

In contrast to Player, this class does not provide convenience methods for initializing a game and running it until the end – it's assumed that users of this class handle this. Instead, onGameStart() and onGameEnd() are exposed, which call the respective functions of all bot modules that have been added to the player. The rationale for this is to enable repeated usage or instantiation of MicroPlayers during a single TorchCraft session.

Constructor & Destructor Documentation

cherrypi::MicroPlayer::MicroPlayer ( std::shared_ptr< tc::Client client)
cherrypi::MicroPlayer::MicroPlayer ( const MicroPlayer )
delete

Member Function Documentation

void cherrypi::MicroPlayer::onGameEnd ( )
void cherrypi::MicroPlayer::onGameStart ( )
MicroPlayer& cherrypi::MicroPlayer::operator= ( const MicroPlayer )
delete

Member Data Documentation

bool cherrypi::MicroPlayer::gameStarted_ = false
protected

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