10 #include <condition_variable> 29 using ClientCommands = std::vector<tc::Client::Command>;
32 BasePlayer(std::shared_ptr<tc::Client> client);
42 void addModule(std::shared_ptr<Module> module);
43 void addModules(std::vector<std::shared_ptr<Module>>
const& modules);
48 auto m = std::dynamic_pointer_cast<T>(module);
57 void queueCmds(
const std::vector<tc::Client::Command>& cmds);
79 virtual void stepModule(std::shared_ptr<Module> module);
94 std::pair<tc::BW::UnitCommandType, std::pair<FrameNum, FrameNum>>;
virtual void preStep()
Definition: baseplayer.cpp:261
Game state.
Definition: state.h:42
void logFailedCommands()
Definition: baseplayer.cpp:316
void setRealtimeFactor(float factor)
Delay step() to make the game run in approx. factor*fastest speed.
Definition: baseplayer.cpp:92
virtual void init()
Definition: baseplayer.h:86
std::vector< tc::Client::Command > pendingCmds_
Definition: baseplayer.h:123
std::pair< tc::BW::UnitCommandType, std::pair< FrameNum, FrameNum >> commandStartEndFrame
Definition: baseplayer.h:94
std::unordered_map< std::shared_ptr< Module >, Duration > moduleTimeSpentAgg_
Definition: baseplayer.h:114
void addModule(std::shared_ptr< Module > module)
Definition: baseplayer.cpp:55
static decltype(std::chrono::milliseconds(42)) const kStepDurationAtFastest
Definition: baseplayer.h:127
int framesDropped_
Definition: baseplayer.h:108
bool initialized_
Definition: baseplayer.h:118
Duration stateUpdateTimeSpent_
Definition: baseplayer.h:115
BasePlayer & operator=(const BasePlayer &)=delete
bool checkConsistency_
Definition: baseplayer.h:104
std::chrono::nanoseconds Duration
Definition: cherrypi.h:36
virtual void stepModule(std::shared_ptr< Module > module)
Definition: baseplayer.cpp:122
int frameskip_
Definition: baseplayer.h:100
std::shared_ptr< Module > top_
Definition: baseplayer.h:112
void dumpTraceAlongReplay(std::string const &replayFile)
Definition: baseplayer.cpp:357
void leave()
Definition: baseplayer.cpp:256
size_t steps() const
Definition: baseplayer.h:82
static decltype(std::chrono::milliseconds(50)) const kMaxStepDuration
Definition: baseplayer.h:125
bool firstStepDone_
Definition: baseplayer.h:119
void setWarnIfSlow(bool warn)
Log a warning if step() exceeds a maximum duration.
Definition: baseplayer.cpp:88
int lastFrameStepped_
Definition: baseplayer.h:107
The main bot object.
Definition: baseplayer.h:28
Duration stateUpdateTimeSpentAgg_
Definition: baseplayer.h:116
bool draw_
Definition: baseplayer.h:121
bool logFailedCommands_
Definition: baseplayer.h:106
virtual ~BasePlayer()
Definition: baseplayer.cpp:47
ClientCommands doStep()
Do the actual per-step work.
Definition: baseplayer.cpp:292
void setDraw(bool draw)
Set whether to post drawing commands (if any are posted).
Definition: baseplayer.cpp:110
State * state()
Definition: baseplayer.h:37
State * state_
Definition: baseplayer.h:111
float realtimeFactor_
Definition: baseplayer.h:109
void setLogFailedCommands(bool log)
Set whether to log failed commands (via VLOG(0)).
Definition: baseplayer.cpp:106
std::shared_ptr< Module > getTopModule() const
Definition: baseplayer.cpp:51
hires_clock::time_point lastStep_
Definition: baseplayer.h:120
void step()
Definition: baseplayer.cpp:135
void setCheckConsistency(bool check)
Set whether to perform consistency checks during the game.
Definition: baseplayer.cpp:96
BasePlayer(std::shared_ptr< tc::Client > client)
Definition: baseplayer.cpp:32
int combineFrames_
Definition: baseplayer.h:101
std::shared_ptr< T > findModule()
Definition: baseplayer.h:46
void stepModules()
Definition: baseplayer.cpp:114
void queueCmds(const std::vector< tc::Client::Command > &cmds)
Add some commands to the queue, they will be executed on next step()
Definition: baseplayer.cpp:353
std::shared_ptr< tc::Client > client_
Definition: baseplayer.h:99
std::vector< std::shared_ptr< Module > > modules_
Definition: baseplayer.h:110
Main namespace for bot-related code.
Definition: areainfo.cpp:17
bool collectTimers_
Definition: baseplayer.h:105
std::unordered_map< std::shared_ptr< Module >, Duration > moduleTimeSpent_
Definition: baseplayer.h:113
static decltype(std::chrono::seconds(9)) const kMaxInitialStepDuration
Definition: baseplayer.h:126
void addModules(std::vector< std::shared_ptr< Module >> const &modules)
Definition: baseplayer.cpp:81
size_t steps_
Definition: baseplayer.h:117
bool nonBlocking_
Definition: baseplayer.h:103
bool warnIfSlow_
Definition: baseplayer.h:102
void setCollectTimers(bool collect)
Set whether to gather timing statistics during the game.
Definition: baseplayer.cpp:100
virtual void postStep()
Definition: baseplayer.cpp:274