TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
tcgame.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 <BWAPI.h>
11 
12 #include <torchcraft/state.h>
13 
14 namespace tcbwapi {
15 
16 // XXX I'm not saying this is clean but it does the job for BWEM
17 class TCGame : public BWAPI::Game {
18  public:
19  TCGame() : BWAPI::Game() {}
20  virtual ~TCGame();
21 
22  // TODO I'm getting linker errors if I attempt to make a proper constructor.
23  void setState(torchcraft::State* s);
24 
25  //
26  // Implemented methods
27  //
28  bool isWalkable(int walkX, int walkY) const override;
29  int getGroundHeight(int tileX, int tileY) const override;
30  bool isBuildable(int tileX, int tileY, bool includeBuildings = false)
31  const override;
32  BWAPI::Unitset const& getStaticNeutralUnits() const override;
33  BWAPI::TilePosition::list const& getStartLocations() const override;
34  int mapWidth() const override;
35  int mapHeight() const override;
36  BWAPI::Unit getUnit(int unitID) const override;
37 
38  private:
39  void throwNotImplemented() const;
40 
41  torchcraft::State* s_ = nullptr;
42 
43  BWAPI::Unitset staticNeutralUnits_;
44  BWAPI::TilePosition::list startLocations_;
45 
46 //
47 // Stubs
48 //
49 #if defined(__clang__)
50 #pragma clang diagnostic push
51 #pragma clang diagnostic ignored "-Wreturn-type"
52 #elif defined(__GNUC__)
53 #pragma GCC diagnostic push
54 #pragma GCC diagnostic ignored "-Wreturn-type"
55 #endif
56  public:
57  const BWAPI::Forceset& getForces() const override {
58  throwNotImplemented();
59  }
60  const BWAPI::Playerset& getPlayers() const override {
61  throwNotImplemented();
62  }
63  const BWAPI::Unitset& getAllUnits() const override {
64  throwNotImplemented();
65  }
66  const BWAPI::Unitset& getMinerals() const override {
67  throwNotImplemented();
68  }
69  const BWAPI::Unitset& getGeysers() const override {
70  throwNotImplemented();
71  }
72  const BWAPI::Unitset& getNeutralUnits() const override {
73  throwNotImplemented();
74  }
75  const BWAPI::Unitset& getStaticMinerals() const override {
76  throwNotImplemented();
77  }
78  const BWAPI::Unitset& getStaticGeysers() const override {
79  throwNotImplemented();
80  }
81  const BWAPI::Bulletset& getBullets() const override {
82  throwNotImplemented();
83  }
84  const BWAPI::Position::list& getNukeDots() const override {
85  throwNotImplemented();
86  }
87  const std::list<BWAPI::Event>& getEvents() const override {
88  throwNotImplemented();
89  }
90  BWAPI::Force getForce(int forceID) const override {
91  throwNotImplemented();
92  }
93  BWAPI::Player getPlayer(int playerID) const override {
94  throwNotImplemented();
95  }
96  BWAPI::Unit indexToUnit(int unitIndex) const override {
97  throwNotImplemented();
98  }
99  BWAPI::Region getRegion(int regionID) const override {
100  throwNotImplemented();
101  }
102  BWAPI::GameType getGameType() const override {
103  throwNotImplemented();
104  }
105  int getLatency() const override {
106  throwNotImplemented();
107  }
108  int getFrameCount() const override {
109  throwNotImplemented();
110  }
111  int getReplayFrameCount() const override {
112  throwNotImplemented();
113  }
114  /// static int bestFPS override { throwNotImplemented(); }
115  int getFPS() const override {
116  throwNotImplemented();
117  }
118  double getAverageFPS() const override {
119  throwNotImplemented();
120  }
121  BWAPI::Position getMousePosition() const override {
122  throwNotImplemented();
123  }
124  bool getMouseState(BWAPI::MouseButton button) const override {
125  throwNotImplemented();
126  }
127  bool getKeyState(BWAPI::Key key) const override {
128  throwNotImplemented();
129  }
130  BWAPI::Position getScreenPosition() const override {
131  throwNotImplemented();
132  }
133  void setScreenPosition(int x, int y) override {
134  throwNotImplemented();
135  }
136  void pingMinimap(int x, int y) override {
137  throwNotImplemented();
138  }
139  bool isFlagEnabled(int flag) const override {
140  throwNotImplemented();
141  }
142  void enableFlag(int flag) override {
143  throwNotImplemented();
144  }
145  BWAPI::Unitset getUnitsInRectangle(
146  int left,
147  int top,
148  int right,
149  int bottom,
150  const BWAPI::UnitFilter& pred = nullptr) const override {
151  throwNotImplemented();
152  }
154  BWAPI::Position center,
155  const BWAPI::UnitFilter& pred = nullptr,
156  int left = 0,
157  int top = 0,
158  int right = 999999,
159  int bottom = 999999) const override {
160  throwNotImplemented();
161  }
162  BWAPI::Unit getBestUnit(
163  const BWAPI::BestUnitFilter& best,
164  const BWAPI::UnitFilter& pred,
165  BWAPI::Position center = BWAPI::Positions::Origin,
166  int radius = 999999) const override {
167  throwNotImplemented();
168  }
169  BWAPI::Error getLastError() const override {
170  throwNotImplemented();
171  }
172  bool setLastError(BWAPI::Error e = BWAPI::Errors::None) const override {
173  throwNotImplemented();
174  }
175  std::string mapFileName() const override {
176  throwNotImplemented();
177  }
178  std::string mapPathName() const override {
179  throwNotImplemented();
180  }
181  std::string mapName() const override {
182  throwNotImplemented();
183  }
184  std::string mapHash() const override {
185  throwNotImplemented();
186  }
187  bool isVisible(int tileX, int tileY) const override {
188  throwNotImplemented();
189  }
190  bool isExplored(int tileX, int tileY) const override {
191  throwNotImplemented();
192  }
193  bool hasCreep(int tileX, int tileY) const override {
194  throwNotImplemented();
195  }
197  int x,
198  int y,
199  BWAPI::UnitType unitType = BWAPI::UnitTypes::None) const override {
200  throwNotImplemented();
201  }
203  BWAPI::TilePosition position,
204  BWAPI::UnitType type,
205  BWAPI::Unit builder = nullptr,
206  bool checkExplored = false) override {
207  throwNotImplemented();
208  }
209  bool canMake(BWAPI::UnitType type, BWAPI::Unit builder = nullptr)
210  const override {
211  throwNotImplemented();
212  }
214  BWAPI::TechType type,
215  BWAPI::Unit unit = nullptr,
216  bool checkCanIssueCommandType = true) override {
217  throwNotImplemented();
218  }
220  BWAPI::UpgradeType type,
221  BWAPI::Unit unit = nullptr,
222  bool checkCanIssueCommandType = true) override {
223  throwNotImplemented();
224  }
225  void vPrintf(const char* format, va_list args) override {
226  throwNotImplemented();
227  }
228  void vSendTextEx(bool toAllies, const char* format, va_list args) override {
229  throwNotImplemented();
230  }
231  bool isInGame() const override {
232  throwNotImplemented();
233  }
234  bool isMultiplayer() const override {
235  throwNotImplemented();
236  }
237  bool isBattleNet() const override {
238  throwNotImplemented();
239  }
240  bool isPaused() const override {
241  throwNotImplemented();
242  }
243  bool isReplay() const override {
244  throwNotImplemented();
245  }
246  void pauseGame() override {
247  throwNotImplemented();
248  }
249  void resumeGame() override {
250  throwNotImplemented();
251  }
252  void leaveGame() override {
253  throwNotImplemented();
254  }
255  void restartGame() override {
256  throwNotImplemented();
257  }
258  void setLocalSpeed(int speed) override {
259  throwNotImplemented();
260  }
261  bool issueCommand(const BWAPI::Unitset& units, BWAPI::UnitCommand command)
262  override {
263  throwNotImplemented();
264  }
265  const BWAPI::Unitset& getSelectedUnits() const override {
266  throwNotImplemented();
267  }
268  BWAPI::Player self() const override {
269  throwNotImplemented();
270  }
271  BWAPI::Player enemy() const override {
272  throwNotImplemented();
273  }
274  BWAPI::Player neutral() const override {
275  throwNotImplemented();
276  }
277  BWAPI::Playerset& allies() override {
278  throwNotImplemented();
279  }
280  BWAPI::Playerset& enemies() override {
281  throwNotImplemented();
282  }
283  BWAPI::Playerset& observers() override {
284  throwNotImplemented();
285  }
287  BWAPI::Text::Size::Enum size = BWAPI::Text::Size::Default) override {
288  throwNotImplemented();
289  }
290  void vDrawText(
291  BWAPI::CoordinateType::Enum ctype,
292  int x,
293  int y,
294  const char* format,
295  va_list arg) override {
296  throwNotImplemented();
297  }
298  void drawBox(
299  BWAPI::CoordinateType::Enum ctype,
300  int left,
301  int top,
302  int right,
303  int bottom,
304  BWAPI::Color color,
305  bool isSolid = false) override {
306  throwNotImplemented();
307  }
309  BWAPI::CoordinateType::Enum ctype,
310  int ax,
311  int ay,
312  int bx,
313  int by,
314  int cx,
315  int cy,
316  BWAPI::Color color,
317  bool isSolid = false) override {
318  throwNotImplemented();
319  }
321  BWAPI::CoordinateType::Enum ctype,
322  int x,
323  int y,
324  int radius,
325  BWAPI::Color color,
326  bool isSolid = false) override {
327  throwNotImplemented();
328  }
330  BWAPI::CoordinateType::Enum ctype,
331  int x,
332  int y,
333  int xrad,
334  int yrad,
335  BWAPI::Color color,
336  bool isSolid = false) override {
337  throwNotImplemented();
338  }
339  void drawDot(
340  BWAPI::CoordinateType::Enum ctype,
341  int x,
342  int y,
343  BWAPI::Color color) override {
344  throwNotImplemented();
345  }
346  void drawLine(
347  BWAPI::CoordinateType::Enum ctype,
348  int x1,
349  int y1,
350  int x2,
351  int y2,
352  BWAPI::Color color) override {
353  throwNotImplemented();
354  }
355  int getLatencyFrames() const override {
356  throwNotImplemented();
357  }
358  int getLatencyTime() const override {
359  throwNotImplemented();
360  }
361  int getRemainingLatencyFrames() const override {
362  throwNotImplemented();
363  }
364  int getRemainingLatencyTime() const override {
365  throwNotImplemented();
366  }
367  int getRevision() const override {
368  throwNotImplemented();
369  }
370  int getClientVersion() const override {
371  throwNotImplemented();
372  }
373  bool isDebug() const override {
374  throwNotImplemented();
375  }
376  bool isLatComEnabled() const override {
377  throwNotImplemented();
378  }
379  void setLatCom(bool isEnabled) override {
380  throwNotImplemented();
381  }
382  bool isGUIEnabled() const override {
383  throwNotImplemented();
384  }
385  void setGUI(bool enabled) override {
386  throwNotImplemented();
387  }
388  int getInstanceNumber() const override {
389  throwNotImplemented();
390  }
391  int getAPM(bool includeSelects = false) const override {
392  throwNotImplemented();
393  }
394  bool setMap(const char* mapFileName) override {
395  throwNotImplemented();
396  }
397  void setFrameSkip(int frameSkip) override {
398  throwNotImplemented();
399  }
401  BWAPI::Player player,
402  bool allied = true,
403  bool alliedVictory = true) override {
404  throwNotImplemented();
405  }
406  bool setVision(BWAPI::Player player, bool enabled = true) override {
407  throwNotImplemented();
408  }
409  int elapsedTime() const override {
410  throwNotImplemented();
411  }
412  void setCommandOptimizationLevel(int level) override {
413  throwNotImplemented();
414  }
415  int countdownTimer() const override {
416  throwNotImplemented();
417  }
418  const BWAPI::Regionset& getAllRegions() const override {
419  throwNotImplemented();
420  }
421  BWAPI::Region getRegionAt(int x, int y) const override {
422  throwNotImplemented();
423  }
424  int getLastEventTime() const override {
425  throwNotImplemented();
426  }
427  bool setRevealAll(bool reveal = true) override {
428  throwNotImplemented();
429  }
430  unsigned getRandomSeed() const override {
431  throwNotImplemented();
432  }
433 #if defined(__clang__)
434 #pragma clang diagnostic pop
435 #elif defined(__GNUC__)
436 #pragma GCC diagnostic pop
437 #endif
438 };
439 
440 } // namespace tcbwapi
BWAPI::GameType getGameType() const override
Definition: tcgame.h:102
void setCommandOptimizationLevel(int level) override
Definition: tcgame.h:412
const std::list< BWAPI::Event > & getEvents() const override
Definition: tcgame.h:87
bool isExplored(int tileX, int tileY) const override
Definition: tcgame.h:190
int getGroundHeight(int tileX, int tileY) const override
Definition: tcgame.cpp:41
int getAPM(bool includeSelects=false) const override
Definition: tcgame.h:391
bool getMouseState(BWAPI::MouseButton button) const override
Definition: tcgame.h:124
int getRemainingLatencyFrames() const override
Definition: tcgame.h:361
bool isBuildable(int tileX, int tileY, bool includeBuildings=false) const override
Definition: tcgame.cpp:52
BWAPI::Playerset & observers() override
Definition: tcgame.h:283
double getAverageFPS() const override
Definition: tcgame.h:118
bool canMake(BWAPI::UnitType type, BWAPI::Unit builder=nullptr) const override
Definition: tcgame.h:209
void resumeGame() override
Definition: tcgame.h:249
BWAPI::Unit getClosestUnitInRectangle(BWAPI::Position center, const BWAPI::UnitFilter &pred=nullptr, int left=0, int top=0, int right=999999, int bottom=999999) const override
Definition: tcgame.h:153
void pingMinimap(int x, int y) override
Definition: tcgame.h:136
std::string mapFileName() const override
Definition: tcgame.h:175
bool canUpgrade(BWAPI::UpgradeType type, BWAPI::Unit unit=nullptr, bool checkCanIssueCommandType=true) override
Definition: tcgame.h:219
Definition: tcgame.h:17
BWAPI::Position getScreenPosition() const override
Definition: tcgame.h:130
BWAPI::TilePosition::list const & getStartLocations() const override
Definition: tcgame.cpp:69
bool isGUIEnabled() const override
Definition: tcgame.h:382
int mapHeight() const override
Definition: tcgame.cpp:77
void vDrawText(BWAPI::CoordinateType::Enum ctype, int x, int y, const char *format, va_list arg) override
Definition: tcgame.h:290
void drawBox(BWAPI::CoordinateType::Enum ctype, int left, int top, int right, int bottom, BWAPI::Color color, bool isSolid=false) override
Definition: tcgame.h:298
void enableFlag(int flag) override
Definition: tcgame.h:142
void drawCircle(BWAPI::CoordinateType::Enum ctype, int x, int y, int radius, BWAPI::Color color, bool isSolid=false) override
Definition: tcgame.h:320
int getReplayFrameCount() const override
Definition: tcgame.h:111
Definition: state.h:25
void setLatCom(bool isEnabled) override
Definition: tcgame.h:379
const BWAPI::Playerset & getPlayers() const override
Definition: tcgame.h:60
void setLocalSpeed(int speed) override
Definition: tcgame.h:258
bool isLatComEnabled() const override
Definition: tcgame.h:376
BWAPI::Playerset & enemies() override
Definition: tcgame.h:280
BWAPI::Player enemy() const override
Definition: tcgame.h:271
bool isMultiplayer() const override
Definition: tcgame.h:234
BWAPI::Position getMousePosition() const override
Definition: tcgame.h:121
BWAPI::Unit getBestUnit(const BWAPI::BestUnitFilter &best, const BWAPI::UnitFilter &pred, BWAPI::Position center=BWAPI::Positions::Origin, int radius=999999) const override
Definition: tcgame.h:162
void setTextSize(BWAPI::Text::Size::Enum size=BWAPI::Text::Size::Default) override
Definition: tcgame.h:286
bool isFlagEnabled(int flag) const override
Definition: tcgame.h:139
bool issueCommand(const BWAPI::Unitset &units, BWAPI::UnitCommand command) override
Definition: tcgame.h:261
bool canBuildHere(BWAPI::TilePosition position, BWAPI::UnitType type, BWAPI::Unit builder=nullptr, bool checkExplored=false) override
Definition: tcgame.h:202
void restartGame() override
Definition: tcgame.h:255
int getRevision() const override
Definition: tcgame.h:367
BWAPI::Error getLastError() const override
Definition: tcgame.h:169
void setScreenPosition(int x, int y) override
Definition: tcgame.h:133
BWAPI::Force getForce(int forceID) const override
Definition: tcgame.h:90
bool hasPowerPrecise(int x, int y, BWAPI::UnitType unitType=BWAPI::UnitTypes::None) const override
Definition: tcgame.h:196
std::string mapName() const override
Definition: tcgame.h:181
BWAPI::Region getRegion(int regionID) const override
Definition: tcgame.h:99
int getClientVersion() const override
Definition: tcgame.h:370
std::string mapPathName() const override
Definition: tcgame.h:178
const BWAPI::Position::list & getNukeDots() const override
Definition: tcgame.h:84
const BWAPI::Unitset & getSelectedUnits() const override
Definition: tcgame.h:265
void setGUI(bool enabled) override
Definition: tcgame.h:385
void leaveGame() override
Definition: tcgame.h:252
int getLatency() const override
Definition: tcgame.h:105
BWAPI::Region getRegionAt(int x, int y) const override
Definition: tcgame.h:421
const BWAPI::Unitset & getGeysers() const override
Definition: tcgame.h:69
const BWAPI::Unitset & getAllUnits() const override
Definition: tcgame.h:63
BWAPI::Playerset & allies() override
Definition: tcgame.h:277
BWAPI::Player neutral() const override
Definition: tcgame.h:274
bool isDebug() const override
Definition: tcgame.h:373
void drawEllipse(BWAPI::CoordinateType::Enum ctype, int x, int y, int xrad, int yrad, BWAPI::Color color, bool isSolid=false) override
Definition: tcgame.h:329
Definition: buildtype.h:15
const BWAPI::Unitset & getMinerals() const override
Definition: tcgame.h:66
const BWAPI::Unitset & getStaticMinerals() const override
Definition: tcgame.h:75
Definition: state.h:43
TCGame()
Definition: tcgame.h:19
bool isVisible(int tileX, int tileY) const override
Definition: tcgame.h:187
bool setVision(BWAPI::Player player, bool enabled=true) override
Definition: tcgame.h:406
void drawDot(BWAPI::CoordinateType::Enum ctype, int x, int y, BWAPI::Color color) override
Definition: tcgame.h:339
BWAPI::Player getPlayer(int playerID) const override
Definition: tcgame.h:93
const BWAPI::Unitset & getStaticGeysers() const override
Definition: tcgame.h:78
void vSendTextEx(bool toAllies, const char *format, va_list args) override
Definition: tcgame.h:228
bool setMap(const char *mapFileName) override
Definition: tcgame.h:394
void drawTriangle(BWAPI::CoordinateType::Enum ctype, int ax, int ay, int bx, int by, int cx, int cy, BWAPI::Color color, bool isSolid=false) override
Definition: tcgame.h:308
int getRemainingLatencyTime() const override
Definition: tcgame.h:364
int getFPS() const override
static int bestFPS override { throwNotImplemented(); }
Definition: tcgame.h:115
bool isReplay() const override
Definition: tcgame.h:243
void vPrintf(const char *format, va_list args) override
Definition: tcgame.h:225
int mapWidth() const override
Definition: tcgame.cpp:73
bool setLastError(BWAPI::Error e=BWAPI::Errors::None) const override
Definition: tcgame.h:172
int elapsedTime() const override
Definition: tcgame.h:409
BWAPI::Unit getUnit(int unitID) const override
Definition: tcgame.cpp:81
int getLatencyFrames() const override
Definition: tcgame.h:355
void drawLine(BWAPI::CoordinateType::Enum ctype, int x1, int y1, int x2, int y2, BWAPI::Color color) override
Definition: tcgame.h:346
void setFrameSkip(int frameSkip) override
Definition: tcgame.h:397
const BWAPI::Unitset & getNeutralUnits() const override
Definition: tcgame.h:72
BWAPI::Unitset getUnitsInRectangle(int left, int top, int right, int bottom, const BWAPI::UnitFilter &pred=nullptr) const override
Definition: tcgame.h:145
BWAPI::Unit indexToUnit(int unitIndex) const override
Definition: tcgame.h:96
bool isPaused() const override
Definition: tcgame.h:240
bool setRevealAll(bool reveal=true) override
Definition: tcgame.h:427
int getLastEventTime() const override
Definition: tcgame.h:424
void setState(torchcraft::State *s)
Definition: tcgame.cpp:16
const BWAPI::Forceset & getForces() const override
Definition: tcgame.h:57
int getFrameCount() const override
Definition: tcgame.h:108
int getInstanceNumber() const override
Definition: tcgame.h:388
bool getKeyState(BWAPI::Key key) const override
Definition: tcgame.h:127
const BWAPI::Regionset & getAllRegions() const override
Definition: tcgame.h:418
bool setAlliance(BWAPI::Player player, bool allied=true, bool alliedVictory=true) override
Definition: tcgame.h:400
bool hasCreep(int tileX, int tileY) const override
Definition: tcgame.h:193
void pauseGame() override
Definition: tcgame.h:246
bool isWalkable(int walkX, int walkY) const override
Definition: tcgame.cpp:32
bool canResearch(BWAPI::TechType type, BWAPI::Unit unit=nullptr, bool checkCanIssueCommandType=true) override
Definition: tcgame.h:213
int countdownTimer() const override
Definition: tcgame.h:415
bool isBattleNet() const override
Definition: tcgame.h:237
BWAPI::Unitset const & getStaticNeutralUnits() const override
Definition: tcgame.cpp:65
bool isInGame() const override
Definition: tcgame.h:231
std::string mapHash() const override
Definition: tcgame.h:184
virtual ~TCGame()
Definition: tcgame.cpp:26
const BWAPI::Bulletset & getBullets() const override
Definition: tcgame.h:81
int getLatencyTime() const override
Definition: tcgame.h:358
unsigned getRandomSeed() const override
Definition: tcgame.h:430