TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
microscenarioprovider.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 "game.h"
11 #include "microplayer.h"
12 #include "modules/once.h"
13 #include "scenarioprovider.h"
14 #include "state.h"
15 
16 namespace cherrypi {
17 
19  public:
20  virtual ~MicroScenarioProvider() = default;
21  void setReplay(std::string const& path) {
22  replay_ = path;
23  }
24 
25  std::pair<std::shared_ptr<BasePlayer>, std::shared_ptr<BasePlayer>>
27  const std::function<void(BasePlayer*)>& setup1,
28  const std::function<void(BasePlayer*)>& setup2) override;
29  void endScenario();
30 
31  std::unique_ptr<Reward> getReward() const;
32 
33  /// It's possible to run this from not the rootdir of the repository,
34  /// in which case you can set the mapPathPrefix to where the maps should be
35  /// found. This is just the path to your cherrypi directory
36  void setMapPathPrefix(const std::string&);
37 
38  protected:
39  virtual FixedScenario getFixedScenario() = 0;
40 
41  std::shared_ptr<tc::Client> client1_;
42  std::shared_ptr<tc::Client> client2_;
43  std::string replay_;
44  std::string mapPathPrefix_;
45 
47 
48  int unitsThisGame_ = 0;
49  int unitsTotal_ = 0;
50  int unitsSeenTotal_ = 0;
51  int scenarioCount_ = 0;
52  int resetCount_ = 0;
53 
54  void endGame();
55  void killAllUnits();
56  void createNewGame();
57  void createNewPlayers();
58  void setupScenario();
59 
61  return !replay_.empty();
62  }
64  return *std::static_pointer_cast<MicroPlayer>(player1_);
65  }
67  return *std::static_pointer_cast<MicroPlayer>(player2_);
68  }
69 };
70 } // namespace cherrypi
MicroPlayer & microPlayer1()
Definition: microscenarioprovider.h:63
std::string replay_
Definition: microscenarioprovider.h:43
bool launchedWithReplay()
Definition: microscenarioprovider.h:60
void endGame()
Definition: microscenarioprovider.cpp:62
std::shared_ptr< BasePlayer > player2_
Definition: scenarioprovider.h:75
std::shared_ptr< tc::Client > client1_
Definition: microscenarioprovider.h:41
std::pair< std::shared_ptr< BasePlayer >, std::shared_ptr< BasePlayer > > startNewScenario(const std::function< void(BasePlayer *)> &setup1, const std::function< void(BasePlayer *)> &setup2) override
Spawns a scenario.
Definition: microscenarioprovider.cpp:317
MicroPlayer & microPlayer2()
Definition: microscenarioprovider.h:66
void killAllUnits()
Definition: microscenarioprovider.cpp:71
The main bot object.
Definition: baseplayer.h:28
std::string mapPathPrefix_
Definition: microscenarioprovider.h:44
int scenarioCount_
Definition: microscenarioprovider.h:51
int unitsTotal_
Definition: microscenarioprovider.h:49
virtual ~MicroScenarioProvider()=default
virtual FixedScenario getFixedScenario()=0
int resetCount_
Definition: microscenarioprovider.h:52
int unitsThisGame_
Definition: microscenarioprovider.h:48
Definition: microscenarioprovider.h:18
void setMapPathPrefix(const std::string &)
It&#39;s possible to run this from not the rootdir of the repository, in which case you can set the mapPa...
Definition: microscenarioprovider.cpp:30
int unitsSeenTotal_
Definition: microscenarioprovider.h:50
void endScenario()
Definition: microscenarioprovider.cpp:38
Definition: scenariospecification.h:57
Base class for providing scenarios.
Definition: scenarioprovider.h:23
void createNewPlayers()
Definition: microscenarioprovider.cpp:110
Main namespace for bot-related code.
Definition: areainfo.cpp:17
The main bot object for training scenarios.
Definition: microplayer.h:28
std::shared_ptr< tc::Client > client2_
Definition: microscenarioprovider.h:42
std::unique_ptr< Reward > getReward() const
Definition: microscenarioprovider.cpp:34
void createNewGame()
Definition: microscenarioprovider.cpp:126
void setReplay(std::string const &path)
Definition: microscenarioprovider.h:21
void setupScenario()
Definition: microscenarioprovider.cpp:142
std::shared_ptr< BasePlayer > player1_
Definition: scenarioprovider.h:74
FixedScenario scenarioNow_
Definition: microscenarioprovider.h:46