11 #include "unitsinfo.h" 13 #include <autogradpp/autograd.h> 14 #include <cereal/cereal.hpp> 15 #include <glog/logging.h> 16 #include <mapbox/variant.hpp> 103 mapbox::util::variant<PlainFeatureType, CustomFeatureType>;
114 static int constexpr kPlainType = 0;
115 static int constexpr kCustomType = 1;
120 : type(type), name(
std::move(name)), numChannels(numChannels) {}
122 : type(type), name(
std::move(name)), numChannels(numChannels) {}
124 : type(other.type), name(other.name), numChannels(other.numChannels) {}
126 : type(
std::move(other.type)),
127 name(
std::move(other.name)),
128 numChannels(other.numChannels) {}
137 type = std::move(other.type);
138 name = std::move(other.name);
139 numChannels = other.numChannels;
146 template <
typename Archive>
153 value =
static_cast<int>(t);
157 value =
static_cast<int>(t);
162 CEREAL_NVP(numChannels));
165 template <
typename Archive>
172 CEREAL_NVP(numChannels));
181 throw std::runtime_error(
182 "Unknown feature kind: " + std::to_string(kind));
193 std::vector<FeatureDescriptor>
desc;
200 int numChannels()
const;
202 Rect boundingBox()
const;
204 Rect boundingBoxAtScale()
const;
206 template <
typename Archive>
208 ar(CEREAL_NVP(tensor),
231 std::vector<PlainFeatureType> types,
248 std::vector<AnyFeatureType> types);
273 irx2 = ir.
right() - 1;
275 offx = mapRect.
x - boundingBox.
x;
276 offy = mapRect.
y - boundingBox.
y;
286 if (pos.
x < irx1 || pos.
y < iry1 || pos.
x > irx2 || pos.
y > iry2) {
Game state.
Definition: state.h:42
void initialize()
Definition: features.cpp:67
T bottom() const
Definition: basetypes.h:221
FeatureData subsampleFeature(FeatureData const &feat, SubsampleMethod method, int factor, int stride)
Applies a spatial subsampling method to a feature.
Definition: features.cpp:259
int offx
Definition: features.h:282
FeatureDescriptor(PlainFeatureType type, std::string name, int numChannels)
Definition: features.h:119
FeatureData featurizePlain(State *state, std::vector< PlainFeatureType > types, Rect boundingBox)
Extracts plain features from the current state.
Definition: features.cpp:131
FeatureDescriptor()
Definition: features.h:118
T right() const
Definition: basetypes.h:215
FeatureDescriptor(CustomFeatureType type, std::string name, int numChannels)
Definition: features.h:121
mapbox::util::variant< PlainFeatureType, CustomFeatureType > AnyFeatureType
Definition: features.h:103
SubsampleMethod
Various methods for spatial subsampling.
Definition: features.h:218
Whether units can walk here or not: 0 or 1; -1 outside of map.
One-hot ground height: channel for height 0, 2, 4 and on the map (4 total)
Whether the corresponding buildtile is reserved.
Grid of X/Y coordinates from (0,0) top left to (N,M) bottom right.
Rect2T< int > Rect
Definition: basetypes.h:309
int scale
Decimation factor wrt walktile resolution.
Definition: features.h:195
FeatureDescriptor(FeatureDescriptor const &other)
Definition: features.h:123
Whether the enemy starts from this position: 0 or 1, -1 outside of map.
T y
Definition: basetypes.h:44
std::vector< FeatureDescriptor > desc
Definition: features.h:193
FeatureData combineFeatures(std::vector< FeatureData > const &feats)
Combines multiple features along channels.
Definition: features.cpp:177
int irx2
Definition: features.h:279
int irx1
Definition: features.h:278
void load(Archive &ar)
Definition: features.h:166
torch::Tensor tensor
Format is [c][y][x].
Definition: features.h:192
User-defined two channel feature.
Whether buildings can be placed here or not: 0 or 1; -1 outside of map.
Rect2T< T > intersected(Rect2T< T > const &r) const
Definition: basetypes.h:266
Whether there is creep here: 0 or 1; -1 outside of map.
T left() const
Definition: basetypes.h:212
Ground height: 0 (low), 1 (high) or 2 (very high); -1 outside of map.
T y
Definition: basetypes.h:185
CustomFeatureType
Defines custom features.
Definition: features.h:87
int numChannels
Definition: features.h:111
AnyFeatureType type
Definition: features.h:109
Represents a collection of spatial feature data.
Definition: features.h:190
void serialize(Archive &ar)
Definition: features.h:207
Whether this walktile contains a doodad that alters the ground height and thus affects visibility and...
PlainFeatureType
Defines a family of "plain" features.
Definition: features.h:36
T top() const
Definition: basetypes.h:218
int offy
Definition: features.h:283
Decribes a specific feature within FeatureData.
Definition: features.h:108
int iry1
Definition: features.h:280
T x
Definition: basetypes.h:184
constexpr Position kInvalidPosition
Definition: basetypes.h:179
Position offset
[0][0] of tensor corresponds to this point (walktiles)
Definition: features.h:197
Calculates which tiles should be revealed by a unit's vision.
Definition: fogofwar.h:23
FeatureData selectFeatures(FeatureData const &feat, std::vector< AnyFeatureType > types)
Selects a subset of features.
Definition: features.cpp:221
std::string name
Definition: features.h:110
Position operator()(Position const &pos) const
Definition: features.h:285
void save(Archive &ar) const
Definition: features.h:147
int iry2
Definition: features.h:281
This map tile has a structure on it, so it's not passable.
FeaturePositionMapper(Rect const &boundingBox, Rect const &mapRect)
Definition: features.h:269
FeatureDescriptor & operator=(FeatureDescriptor const &other)
Definition: features.h:130
FeatureDescriptor(FeatureDescriptor &&other)
Definition: features.h:125
Maps walktile positions to feature positions for a given bounding box.
Definition: features.h:268
T x
Definition: basetypes.h:43
Main namespace for bot-related code.
Definition: areainfo.cpp:17
Whether this position is a starting location.
User-defined single-channel feature.
Vec2T< int > Position
Definition: basetypes.h:178
FeatureDescriptor & operator=(FeatureDescriptor &&other)
Definition: features.h:136