TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
replayer.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 "src/gameutils/openbwprocess.h"
12 
13 #include <torchcraft/client.h>
14 
15 #include <vector>
16 
17 namespace cherrypi {
18 
19 class State;
20 
22  std::string replayPath;
23  bool forceGui = false;
24  int combineFrames = 3;
25 };
26 
27 /**
28  * Play back a Brood War replay using OpenBW
29  *
30  * Provides a TorchCraft view of the game state.
31  */
32 class TCReplayer {
33  public:
34  TCReplayer(std::string replayPath);
36  virtual ~TCReplayer(){};
37 
38  torchcraft::State* tcstate() const;
39 
40  void init();
41  void step();
42  void run();
43  bool isComplete() {
44  return tcstate()->game_ended;
45  }
46 
47  virtual void onStep(){};
48 
49  protected:
50  ReplayerConfiguration configuration_;
51  std::unique_ptr<OpenBwProcess> openbw_;
52  std::shared_ptr<torchcraft::Client> client_;
53  bool initialized_ = false;
54 };
55 
56 /**
57  * Play back a Brood War replay using OpenBW
58  *
59  * Runs the bot alongside the replay, and provides access to the bot's state.
60  */
61 class Replayer : public TCReplayer {
62  public:
63  Replayer(std::string replayPath);
65  virtual ~Replayer() override{};
66 
67  /// Convenience wrapper for State::setPerspective()
68  void setPerspective(PlayerId);
69 
70  State* state();
71 
72  virtual void onStep() override;
73 
74  protected:
75  std::unique_ptr<State> state_;
76 };
77 
78 } // namespace cherrypi
virtual void onStep()
Definition: replayer.h:47
Game state.
Definition: state.h:42
Definition: replayer.h:21
std::shared_ptr< torchcraft::Client > client_
Definition: replayer.h:52
bool game_ended
Definition: state.h:79
std::string replayPath
Definition: replayer.h:22
std::unique_ptr< State > state_
Definition: replayer.h:75
int combineFrames
Definition: replayer.h:24
virtual ~Replayer() override
Definition: replayer.h:65
bool isComplete()
Definition: replayer.h:43
Definition: state.h:43
std::unique_ptr< OpenBwProcess > openbw_
Definition: replayer.h:51
Play back a Brood War replay using OpenBW.
Definition: replayer.h:32
virtual ~TCReplayer()
Definition: replayer.h:36
Play back a Brood War replay using OpenBW.
Definition: replayer.h:61
int PlayerId
Definition: basetypes.h:21
Main namespace for bot-related code.
Definition: areainfo.cpp:17
bool forceGui
Definition: replayer.h:23
void init(int64_t randomSeed)
Definition: cherrypi.cpp:293