TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
combatsim.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 <array>
11 #include <vector>
12 
13 namespace cherrypi {
14 
15 struct BuildType;
16 struct Unit;
17 
18 /**
19  * Predicts the outcome of a hypothetical fight by simulating unit
20  * movements/attacks.
21  *
22  * Uses a high speed/low precision approximation of Brood War mechanics,
23  * ignoring elements like collisions, splash damage, accleration, turn rates,
24  * attack animations, and spells.
25  */
26 class CombatSim {
27  public:
28  struct SimUnit {
29  int x = 0;
30  int y = 0;
31  double hp = 0.0;
32  double shields = 0.0;
33  int armor = 0;
34  int maxSpeed = 0;
35  bool flying = false;
36  bool underDarkSwarm = false;
37  const BuildType* type = nullptr;
38  SimUnit* target = nullptr;
39  bool targetInRange = false;
40 
41  int cooldownUntil = 0;
42  int groundDamage = 0;
43  int airDamage = 0;
45  int airDamageType = 0;
46  int groundRange = 0;
47  int airRange = 0;
48  };
49 
50  struct Team {
51  double startHp = 0.0;
52  double endHp = 0.0;
53  std::vector<SimUnit> units;
54  };
55 
56  double speedMult = 1.0;
57  std::array<Team, 2> teams;
58 
59  bool addUnit(Unit* u);
60 
61  void run(int frames);
62 };
63 } // namespace cherrypi
double speedMult
Definition: combatsim.h:56
Predicts the outcome of a hypothetical fight by simulating unit movements/attacks.
Definition: combatsim.h:26
Definition: combatsim.h:50
int airRange
Definition: combatsim.h:47
int cooldownUntil
Definition: combatsim.h:41
Represents and holds information about buildable types (units, upgrades, techs).
Definition: buildtype.h:36
Definition: combatsim.h:28
int airDamage
Definition: combatsim.h:43
int x
Definition: combatsim.h:29
void run(int frames)
Definition: combatsim.cpp:96
replayer::Unit Unit
Definition: state.h:36
SimUnit * target
Definition: combatsim.h:38
Represents a unit in the game.
Definition: unitsinfo.h:35
double shields
Definition: combatsim.h:32
bool flying
Definition: combatsim.h:35
int groundRange
Definition: combatsim.h:46
double hp
Definition: combatsim.h:31
int maxSpeed
Definition: combatsim.h:34
int groundDamage
Definition: combatsim.h:42
bool targetInRange
Definition: combatsim.h:39
const BuildType * type
Definition: combatsim.h:37
int airDamageType
Definition: combatsim.h:45
std::array< Team, 2 > teams
Definition: combatsim.h:57
int groundDamageType
Definition: combatsim.h:44
std::vector< SimUnit > units
Definition: combatsim.h:53
int armor
Definition: combatsim.h:33
bool underDarkSwarm
Definition: combatsim.h:36
Main namespace for bot-related code.
Definition: areainfo.cpp:17
bool addUnit(Unit *u)
Definition: combatsim.cpp:39
int y
Definition: combatsim.h:30