TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
botcli-inl.h
1 /*
2  * Copyright (c) 2017-present, Facebook, Inc.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #pragma once
9 
10 #include "cherrypi.h"
11 #include "common/rand.h"
12 #include "modules.h"
13 #include "player.h"
14 #include "utils.h"
15 
16 #include <gflags/gflags.h>
17 
18 /**
19  * This file pulls in command-line flags that are useful for programs that run
20  * the full player-> There's also a setupPlayerFromCli() method that sets up a
21  * `Player` instance accordingly.
22  */
23 
24 // Command line flags
25 DEFINE_string(
26  modules,
28  "Comma-separated list of bot modules");
29 DEFINE_int32(frameskip, 1, "Frame skip for screen updates");
30 DEFINE_int32(timeout, 120000, "Timeout for TorchCraft connection");
31 DEFINE_int32(seed, -1, "Random seed. Used default seed if -1");
32 DEFINE_int32(
33  realtime_factor,
34  -1,
35  "Delay execution to achieve desired realtime factor");
36 DEFINE_bool(
37  warn_if_slow,
38  true,
39  "Warn if stepping through modules takes too long");
40 DEFINE_bool(
41  blocking,
42  false,
43  "Run bot step in main thread, possibly blocking game execution");
44 DEFINE_bool(logsinktostderr, true, "Log sink to stderror.");
45 DEFINE_string(logsinkdir, "", "Optional directory to write sink log files");
46 DEFINE_bool(consistency, true, "Run consistency checks during bot execution");
47 DEFINE_bool(timers, true, "Measure elapsed time in bot modules");
48 DEFINE_bool(log_failed_commands, false, "Log failed Torchcraft/BWAPI commands");
49 DEFINE_bool(draw, false, "Enable drawing");
50 DEFINE_string(
51  trace_along_replay_file,
52  "",
53  "Path to a replay file (.rep) along which we will trace the bot internal "
54  "state. Disabled if empty");
55 DECLARE_string(umm_path);
56 DEFINE_bool(map_hack, false, "Enable map hack");
57 
58 namespace cherrypi {
59 
60 void setupPlayerFromCli(Player* player) {
61  // Configure according to flags defined above
62  player->setFrameskip(FLAGS_frameskip);
63  player->setRealtimeFactor(FLAGS_realtime_factor);
64  player->setWarnIfSlow(FLAGS_warn_if_slow);
65  player->setNonBlocking(!FLAGS_blocking);
66  player->setCheckConsistency(FLAGS_consistency);
67  player->setCollectTimers(FLAGS_timers);
68  player->setLogFailedCommands(FLAGS_log_failed_commands);
69  player->setDraw(FLAGS_draw);
70  player->setMapHack(FLAGS_map_hack);
71 
72  // Add modules
74  for (auto name : utils::stringSplit(FLAGS_modules, ',')) {
75  if (!name.empty()) {
76  player->addModule(Module::make(name));
77  }
78  }
80  if (!FLAGS_trace_along_replay_file.empty()) {
81  player->dumpTraceAlongReplay(FLAGS_trace_along_replay_file);
82  }
83 }
84 
85 } // namespace cherrypi
void setRealtimeFactor(float factor)
Delay step() to make the game run in approx. factor*fastest speed.
Definition: baseplayer.cpp:92
void addModule(std::shared_ptr< Module > module)
Definition: baseplayer.cpp:55
static std::shared_ptr< T > make(Args &&...args)
Definition: module.h:35
void dumpTraceAlongReplay(std::string const &replayFile)
Definition: baseplayer.cpp:357
void setWarnIfSlow(bool warn)
Log a warning if step() exceeds a maximum duration.
Definition: baseplayer.cpp:88
char constexpr kDefaultModules[]
The default set of modules.
Definition: modules.h:35
void setFrameskip(int n)
UI update frequency of Broodwar instance. Set this before calling init().
Definition: player.cpp:24
void setupPlayerFromCli(Player *player)
Definition: botcli-inl.h:60
void setMapHack(bool on)
Definition: player.h:46
void setDraw(bool draw)
Set whether to post drawing commands (if any are posted).
Definition: baseplayer.cpp:110
void setLogFailedCommands(bool log)
Set whether to log failed commands (via VLOG(0)).
Definition: baseplayer.cpp:106
void setCheckConsistency(bool check)
Set whether to perform consistency checks during the game.
Definition: baseplayer.cpp:96
void setNonBlocking(bool nonBlocking)
Run bot step in separate thread to prevent blocking game execution.
Definition: player.cpp:38
Main namespace for bot-related code.
Definition: areainfo.cpp:17
char constexpr kAutoTopModule[]
Definition: modules.h:30
char constexpr kAutoBottomModule[]
Definition: modules.h:31
The main bot object for complete games of StarCraft.
Definition: player.h:29
void setCollectTimers(bool collect)
Set whether to gather timing statistics during the game.
Definition: baseplayer.cpp:100