SC2API
An API for AI for StarCraft II
sc2_score.h
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include "sc2_proto_interface.h"
7 #include "sc2_gametypes.h"
8 #include <vector>
9 #include <string>
10 #include <stdint.h>
11 
12 namespace sc2 {
13 
15 enum class ScoreType {
17  Curriculum = 1,
19  Melee = 2
20 };
21 
22 struct ScoreEntry {
23  std::string name;
24  int offset;
25  bool use;
26  bool nonzero;
27 
28  ScoreEntry() :
29  offset(0),
30  use(true),
31  nonzero(false) {
32  }
33 };
34 
35 #define SET_ENTRY_BASE(STRUCTNAME, ENTRYNAME) \
36  { \
37  ScoreEntry new_entry; \
38  new_entry.offset += (int)int64_t(&(((STRUCTNAME*)0)->ENTRYNAME)); \
39  new_entry.name += #STRUCTNAME"."#ENTRYNAME; \
40  entries.push_back(new_entry); \
41  }
42 
43 #define SET_ENTRY_BASE_STRUCT(STRUCTNAME, ENTRYNAME) \
44  { \
45  ScoreEntry base_entry; \
46  base_entry.offset += (int)int64_t(&(((STRUCTNAME*)0)->ENTRYNAME)); \
47  base_entry.name += #STRUCTNAME"."#ENTRYNAME; \
48  ((STRUCTNAME*)0)->ENTRYNAME.AddEntries(base_entry, entries); \
49  }
50 
51 #define SET_ENTRY(STRUCTNAME, ENTRYNAME) \
52  { \
53  ScoreEntry new_entry = base; \
54  new_entry.offset += (int)int64_t(&(((STRUCTNAME*)0)->ENTRYNAME)); \
55  new_entry.name += "."#ENTRYNAME; \
56  entries.push_back(new_entry); \
57  }
58 
59 #define SET_ENTRY_STRUCT(STRUCTNAME, ENTRYNAME) \
60  { \
61  ScoreEntry new_entry = base; \
62  new_entry.offset += (int)int64_t(&(((STRUCTNAME*)0)->ENTRYNAME)); \
63  new_entry.name += "."#ENTRYNAME; \
64  ((STRUCTNAME*)0)->ENTRYNAME.AddEntries(new_entry, entries); \
65  }
66 
69  float none;
70  float army;
71  float economy;
72  float technology;
73  float upgrade;
74 
76 
77  static void AddEntries(ScoreEntry base, std::vector<ScoreEntry>& entries) {
78  SET_ENTRY(CategoryScoreDetails, none)
79  SET_ENTRY(CategoryScoreDetails, army)
80  SET_ENTRY(CategoryScoreDetails, economy)
81  SET_ENTRY(CategoryScoreDetails, technology)
82  SET_ENTRY(CategoryScoreDetails, upgrade)
83  }
84 };
85 
88  float life;
89  float shields;
90  float energy;
91 
93 
94  static void AddEntries(ScoreEntry base, std::vector<ScoreEntry>& entries) {
95  SET_ENTRY(VitalScoreDetails, life)
96  SET_ENTRY(VitalScoreDetails, shields)
97  SET_ENTRY(VitalScoreDetails, energy)
98  }
99 };
100 
102 struct ScoreDetails {
103  float idle_production_time;
104  float idle_worker_time;
105 
106  float total_value_units;
107  float total_value_structures;
108 
109  // Note the "killed_value" fields are a combination of minerals, vespene and a human designer guess. Maybe useful as a delta.
110  // The weighting of the combination and the human designer guess is different (not symmetric) with the "total_value" fields!
111  float killed_value_units;
112  float killed_value_structures;
113 
114  float collected_minerals;
115  float collected_vespene;
116 
117  float collection_rate_minerals;
118  float collection_rate_vespene;
119 
120  float spent_minerals;
121  float spent_vespene;
122 
123  CategoryScoreDetails food_used;
124 
125  CategoryScoreDetails killed_minerals;
126  CategoryScoreDetails killed_vespene;
127 
128  CategoryScoreDetails lost_minerals;
129  CategoryScoreDetails lost_vespene;
130 
131  CategoryScoreDetails friendly_fire_minerals;
132  CategoryScoreDetails friendly_fire_vespene;
133 
134  CategoryScoreDetails used_minerals;
135  CategoryScoreDetails used_vespene;
136 
137  CategoryScoreDetails total_used_minerals;
138  CategoryScoreDetails total_used_vespene;
139 
140  VitalScoreDetails total_damage_dealt;
141  VitalScoreDetails total_damage_taken;
142  VitalScoreDetails total_healed;
143 
144  ScoreDetails();
145 
146  static void AddEntries(ScoreEntry base, std::vector<ScoreEntry>& entries) {
147  SET_ENTRY(ScoreDetails, idle_production_time)
148  SET_ENTRY(ScoreDetails, idle_worker_time)
149  SET_ENTRY(ScoreDetails, total_value_units)
150  SET_ENTRY(ScoreDetails, total_value_structures)
151  SET_ENTRY(ScoreDetails, killed_value_units)
152  SET_ENTRY(ScoreDetails, killed_value_structures)
153  SET_ENTRY(ScoreDetails, collected_minerals)
154  SET_ENTRY(ScoreDetails, collected_vespene)
155  SET_ENTRY(ScoreDetails, collection_rate_minerals)
156  SET_ENTRY(ScoreDetails, collection_rate_vespene)
157  SET_ENTRY(ScoreDetails, spent_minerals)
158  SET_ENTRY(ScoreDetails, spent_vespene)
159 
160  SET_ENTRY_STRUCT(ScoreDetails, food_used)
161  SET_ENTRY_STRUCT(ScoreDetails, killed_minerals)
162  SET_ENTRY_STRUCT(ScoreDetails, killed_vespene)
163  SET_ENTRY_STRUCT(ScoreDetails, lost_minerals)
164  SET_ENTRY_STRUCT(ScoreDetails, lost_vespene)
165  SET_ENTRY_STRUCT(ScoreDetails, friendly_fire_minerals)
166  SET_ENTRY_STRUCT(ScoreDetails, friendly_fire_vespene)
167  SET_ENTRY_STRUCT(ScoreDetails, used_minerals)
168  SET_ENTRY_STRUCT(ScoreDetails, used_vespene)
169  SET_ENTRY_STRUCT(ScoreDetails, total_used_minerals)
170  SET_ENTRY_STRUCT(ScoreDetails, total_used_vespene)
171 
172  SET_ENTRY_STRUCT(ScoreDetails, total_damage_dealt)
173  SET_ENTRY_STRUCT(ScoreDetails, total_damage_taken)
174  SET_ENTRY_STRUCT(ScoreDetails, total_healed)
175  }
176 };
177 
179 struct Score {
180  ScoreType score_type;
181  float score; // Note: check score_type to know whether this is a melee score or curriculum score
182  ScoreDetails score_details;
183 
184  // Access as a flat list of floats.
185  static const int float_count_ = sizeof(ScoreDetails) / sizeof(float) + 1;
186  const float* RawFloats() const { return &score; }
187 
188  Score();
189 
190  static void AddEntries(std::vector<ScoreEntry>& entries) {
191  SET_ENTRY_BASE(Score, score)
192  SET_ENTRY_BASE_STRUCT(Score, score_details)
193  }
194 
195  bool IsEqual(const Score& other_score) const;
196 };
197 
198 }
Score for vitals.
Definition: sc2_score.h:87
Scores.
Definition: sc2_score.h:179
Definition: sc2_score.h:22
Definition: sc2_action.h:9
Detailed scores.
Definition: sc2_score.h:102
ScoreType
Source of a score.
Definition: sc2_score.h:15
Types used in setting up a game.
Score by category.
Definition: sc2_score.h:68