TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
scenariospecification.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 "rewards.h"
11 #include "src/modules/lambda.h"
12 #include "state.h"
13 
14 namespace cherrypi {
15 
16 struct SpawnPosition {
17  int count;
18  tc::BW::UnitType type;
19  int x;
20  int y;
21  double spreadX = 0.0;
22  double spreadY = 0.0;
23  int health = -1;
24  int shields = -1;
25  int energy = -1;
26 };
27 
29  torchcraft::BW::UpgradeType upgradeType;
30  int level = 1;
31 };
32 
34  std::vector<torchcraft::BW::TechType> techs;
35  std::vector<ScenarioUpgradeLevel> upgrades;
36  std::vector<SpawnPosition> units;
37 
38  int getUpgradeLevel(int upgradeType) const {
39  for (auto& upgrade : upgrades) {
40  if (upgrade.upgradeType ==
41  torchcraft::BW::UpgradeType::_from_integral_unchecked(upgradeType)) {
42  return upgrade.level;
43  }
44  }
45  return 0;
46  }
47 
48  int hasTech(int techType) const {
49  return techs.end() !=
50  std::find(
51  techs.begin(),
52  techs.end(),
53  torchcraft::BW::TechType::_from_integral_unchecked(techType));
54  }
55 };
56 
57 struct FixedScenario {
58  std::string name;
59  std::string map{"test/maps/micro-empty2.scm"};
60  std::function<std::unique_ptr<Reward>()> reward = []() {
61  return combatReward();
62  };
63  std::vector<FixedScenarioPlayer> players = {{}, {}};
64  std::vector<LambdaModule::StepFunctionState> stepFunctions;
65 
66  FixedScenario& addTech(int player, torchcraft::BW::TechType tech) {
67  players[player].techs.push_back(tech);
68  return *this;
69  }
70 
72  addUpgrade(int player, torchcraft::BW::UpgradeType upgrade, int level = 1) {
73  players[player].upgrades.push_back({upgrade, level});
74  return *this;
75  }
76 
77  std::vector<SpawnPosition>& allies() {
78  return players[0].units;
79  }
80  std::vector<SpawnPosition>& enemies() {
81  return players[1].units;
82  }
83 };
84 
86  std::string name;
87  std::vector<FixedScenario> scenarios = std::vector<FixedScenario>();
88 
89  FixedScenario& add(std::string name) {
90  scenarios.emplace_back(FixedScenario{name});
91  return scenarios.back();
92  };
93 };
94 
95 } // namespace cherrypi
Definition: scenariospecification.h:16
Definition: scenariospecification.h:33
FixedScenario & add(std::string name)
Definition: scenariospecification.h:89
FixedScenario & addUpgrade(int player, torchcraft::BW::UpgradeType upgrade, int level=1)
Definition: scenariospecification.h:72
std::vector< SpawnPosition > units
Definition: scenariospecification.h:36
int y
Definition: scenariospecification.h:20
tc::BW::UnitType type
Definition: scenariospecification.h:18
std::vector< SpawnPosition > & allies()
Definition: scenariospecification.h:77
double spreadY
Definition: scenariospecification.h:22
std::vector< torchcraft::BW::TechType > techs
Definition: scenariospecification.h:34
std::vector< ScenarioUpgradeLevel > upgrades
Definition: scenariospecification.h:35
int count
Definition: scenariospecification.h:17
int shields
Definition: scenariospecification.h:24
Definition: scenariospecification.h:85
Definition: scenariospecification.h:28
int x
Definition: scenariospecification.h:19
FixedScenario & addTech(int player, torchcraft::BW::TechType tech)
Definition: scenariospecification.h:66
torchcraft::BW::UpgradeType upgradeType
Definition: scenariospecification.h:29
std::string name
Definition: scenariospecification.h:86
int getUpgradeLevel(int upgradeType) const
Definition: scenariospecification.h:38
int energy
Definition: scenariospecification.h:25
std::unique_ptr< Reward > combatReward()
Definition: rewards.cpp:55
std::vector< SpawnPosition > & enemies()
Definition: scenariospecification.h:80
Definition: scenariospecification.h:57
std::string name
Definition: scenariospecification.h:58
std::vector< LambdaModule::StepFunctionState > stepFunctions
Definition: scenariospecification.h:64
Main namespace for bot-related code.
Definition: areainfo.cpp:17
double spreadX
Definition: scenariospecification.h:21
int health
Definition: scenariospecification.h:23
int hasTech(int techType) const
Definition: scenariospecification.h:48