TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
base.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 "../modules/autobuild.h"
11 
12 #include "../modules/builderhelper.h"
13 #include "registry.h"
14 #include "utils.h"
15 
16 namespace cherrypi {
17 
18 namespace buildorders {
19 std::shared_ptr<AutoBuildTask>
20 createTask(UpcId srcUpcId, std::string name, State* state, Module* module);
21 } // namespace buildorders
22 
23 class ABBOBase : public AutoBuildTask {
24  public:
25  ABBOBase(UpcId upcId, State* state, Module* module)
26  : AutoBuildTask(upcId, state, module) {}
27 
29  bool canExpand = false;
30  bool shouldExpand = false;
31  bool forceExpand = false;
32  bool preferSafeExpansions = true;
33 
34  int enemyWorkerCount = 0;
35  int enemyGasCount = 0;
36  int enemyZealotCount = 0;
37  int enemyDragoonCount = 0;
38  int enemyDarkTemplarCount = 0;
39  int enemyHighTemplarCount = 0;
40  int enemyArchonCount = 0;
41  int enemyReaverCount = 0;
42  int enemyVultureCount = 0;
43  int enemyGoliathCount = 0;
44  int enemyTankCount = 0;
45  int enemyMissileTurretCount = 0;
46  int enemyCorsairCount = 0;
47  int enemyScoutCount = 0;
48  int enemyObserverCount = 0;
49  int enemyWraithCount = 0;
50  int enemyValkyrieCount = 0;
51  int enemyBattlecruiserCount = 0;
52  int enemyStaticDefenceCount = 0;
53  int enemyBarracksCount = 0;
54  int enemyRefineryCount = 0;
55  int enemyAcademyCount = 0;
56  int enemyGatewayCount = 0;
57  int enemyCyberneticsCoreCount = 0;
58  int enemyStargateCount = 0;
59  int enemyForgeCount = 0;
60  int enemyZerglingCount = 0;
61  int enemyHydraliskCount = 0;
62  int enemyMutaliskCount = 0;
63  int enemyScourgeCount = 0;
64  int enemySunkenCount = 0;
65  int enemySporeCount = 0;
66  int enemyMarineCount = 0;
67  int enemyMedicCount = 0;
68  int enemyFirebatCount = 0;
69  int enemyFactoryCount = 0;
70  int enemyLairCount = 0;
71  int enemySpireCount = 0;
72  int enemyCloakedUnitCount = 0;
73  bool enemyHasExpanded = false;
74  bool enemyIsRushing = false; // TODO detect for protoss / zerg
75  int enemyBuildingCount = 0;
76  int enemyScienceVesselCount = 0;
77  int enemyArbiterCount = 0;
78  int enemyShuttleCount = 0;
79  int enemyResourceDepots = 0;
80  int enemyGasUnits = 0;
81  int enemyTemplarArchivesCount = 0;
82 
83  int myCompletedHatchCount = 0;
84  int myLarvaCount = 0;
85  int mySunkenCount = 0;
86  int mySporeCount = 0;
87  int myDroneCount = 0;
88  int myZerglingCount = 0;
89  int myHydraliskCount = 0;
90  int myMutaliskCount = 0;
91  int myScourgeCount = 0;
92  int myLurkerCount = 0;
93  int myGuardianCount = 0;
94  int myUltraliskCount = 0;
95  int myDefilerCount = 0;
96 
97  int mineralFields = 0;
98  int geysers = 0;
104  bool hasFoundEnemyBase = false;
106  bool weArePlanningExpansion = false;
107  int currentFrame = 0;
108 
109  int bases = 0;
110 
111  bool isLosingAnOverlord = false;
112 
113  Position lastFindNaturalDefencePosEnemyPos{-1, -1};
114 
115  std::vector<uint8_t> inBaseArea =
116  std::vector<uint8_t>(TilesInfo::tilesWidth * TilesInfo::tilesHeight);
117  FrameNum lastUpdateInBaseArea = 0;
118 
119  double armySupply = 0.0;
120  double groundArmySupply = 0.0;
121  double airArmySupply = 0.0;
122 
123  double enemySupplyInOurBase = 0.0;
124  double enemyArmySupplyInOurBase = 0.0;
125  double enemyArmySupply = 0.0;
126  double enemyGroundArmySupply = 0.0;
127  double enemyAirArmySupply = 0.0;
128  double enemyAntiAirArmySupply = 0.0;
129  double enemyAttackingArmySupply = 0.0;
130  double enemyAttackingGroundArmySupply = 0.0;
131  double enemyAttackingAirArmySupply = 0.0;
132  int enemyAttackingWorkerCount = 0;
133  double enemyLargeArmySupply = 0.0;
134  double enemySmallArmySupply = 0.0;
135  double enemyBiologicalArmySupply = 0.0;
136  double enemyProximity = 0.0;
137 
138  int enemyProxyBuildingCount = 0;
139  int enemyProxyGatewayCount = 0;
140  int enemyProxyBarracksCount = 0;
141  int enemyProxyForgeCount = 0;
142  int enemyProxyCannonCount = 0;
143 
144  bool enemyForgeIsSpinning = false;
145 
146  tc::BW::Race enemyRace = tc::BW::Race::Unknown;
147 
148  bool autoExpand = true;
149  bool autoUpgrade = true;
150  bool expandNearest = false;
151  bool buildExtraOverlordsIfLosingThem = true;
152 
153  void findNaturalDefencePos(State*);
154 
155  Position getStaticDefencePos(State*, const BuildType* type);
156 
157  private:
158  void buildZergStaticDefense(
160  int numberDesired,
161  const BuildType* morphedType,
162  Position position,
163  bool morphFirst);
164 
165  protected:
166  virtual void draw(State* state) override;
167 
168  public:
169  void buildSunkens(
171  int n,
172  Position = {},
173  bool morphFirst = false);
174  void buildSpores(
176  int n,
177  Position = {},
178  bool morphFirst = false);
179  void morphSunkens(autobuild::BuildState&, int n = 1000);
180  void morphSpores(autobuild::BuildState&, int n = 1000);
181  void takeNBases(autobuild::BuildState&, int n);
182  void expand(autobuild::BuildState& st);
183 
184  void calculateArmySupply(const autobuild::BuildState& st);
185 
186  Position findHatcheryPosNear(Position seedPos);
187 
188  Position findSunkenPosNear(
189  const BuildType* type,
190  Position seedPos,
191  bool coverMineralsOnly = false);
192 
193  Position findSunkenPos(
194  const BuildType* type,
195  bool mainBaseOnly = false,
196  bool coverMineralsOnly = false);
197 
198  virtual void preBuild2(autobuild::BuildState& st) {}
199  virtual void preBuild(autobuild::BuildState& st) override final;
200  virtual void postBuild2(autobuild::BuildState& st) {}
201  virtual void postBuild(autobuild::BuildState& st) override final;
203  virtual void buildStep(autobuild::BuildState&) override final;
204 };
205 } // namespace cherrypi
Game state.
Definition: state.h:42
int FrameNum
Definition: basetypes.h:22
Position enemyBasePos
Definition: base.h:103
Position mainNaturalChoke
Definition: base.h:102
Represents and holds information about buildable types (units, upgrades, techs).
Definition: buildtype.h:36
virtual void buildStep2(autobuild::BuildState &)
Definition: base.h:202
Position naturalPos
Definition: base.h:100
Describes a state of the game, either now or in a hypothetical future, for use in AutoBuilds...
Definition: autobuild.h:54
Position nextBase
Definition: base.h:28
Definition: base.h:23
static const unsigned tilesWidth
Definition: tilesinfo.h:98
static const unsigned tilesHeight
Definition: tilesinfo.h:99
virtual void preBuild2(autobuild::BuildState &st)
Definition: base.h:198
virtual void postBuild2(autobuild::BuildState &st)
Definition: base.h:200
Position nextStaticDefencePos
Definition: base.h:105
Position naturalDefencePos
Definition: base.h:101
std::shared_ptr< AutoBuildTask > createTask(UpcId srcUpcId, std::string name, State *state, Module *module)
Definition: base.cpp:21
AutoBuildTasks are "build orders" in the colloquial sense.
Definition: autobuild.h:107
Main namespace for bot-related code.
Definition: areainfo.cpp:17
int UpcId
Definition: basetypes.h:23
Position homePosition
Definition: base.h:99
Interface for bot modules.
Definition: module.h:30
ABBOBase(UpcId upcId, State *state, Module *module)
Definition: base.h:25