10 #include "features/features.h" 11 #include "features/jitter.h" 40 template <
typename Archive>
42 ar(CEREAL_NVP(boundingBox), CEREAL_NVP(positions), CEREAL_NVP(data));
47 std::shared_ptr<BaseJitter>
jitter = std::make_shared<NoJitter>();
96 name =
"UnitPresence";
117 static int constexpr kNumUnitTypes = 233 * 3;
128 std::unordered_map<int, int>
const& channelValues)
const;
133 acc[0] = unit->
type->
unit + 233 * 0;
135 acc[0] = unit->
type->
unit + 233 * 1;
137 acc[0] = unit->
type->
unit + 233 * 2;
154 static int constexpr kNumUnitTypes = 118 * 2;
159 return typemap_->at(unitType);
162 return itypemap_->at(mappedType);
170 acc[0] = mapType(unit->
type->
unit) + 118 * 0;
172 acc[0] = mapType(unit->
type->
unit) + 118 * 1;
189 static int constexpr kNumUnitTypes = 118 * 2;
208 static int constexpr kNumUnitFlags = 52;
213 numChannels = kNumUnitFlags;
218 for (
auto flag = 0; flag < kNumUnitFlags; flag++) {
219 acc[flag] = (unit->
unit.
flags & (1 << flag)) ? 1 : 0;
225 static constexpr
int kNumChannels =
231 numChannels = kNumChannels;
244 #define GEN_SPARSE_UNIT_ATTRIBUTE_FEATURIZER(NAME, ATTR) \ 245 struct Unit##NAME##Featurizer : UnitAttributeFeaturizer { \ 246 Unit##NAME##Featurizer() { \ 247 type = CustomFeatureType::Unit##NAME; \ 248 name = "Unit" #NAME; \ 253 virtual void extractUnit(TensorDest acc, Unit* unit) override { \ 254 acc[0] = unit->unit.ATTR; \ 263 #undef GEN_SPARSE_UNIT_ATTRIBUTE_FEATURIZER Game state.
Definition: state.h:42
int numChannels
Definition: unitsfeatures.h:53
torch::Tensor positions
Definition: unitsfeatures.h:37
UnitTypeFeaturizer()
Definition: unitsfeatures.h:119
UnitPresenceFeaturizer()
Definition: unitsfeatures.h:94
static int constexpr kNumUnitFlags
Definition: unitsfeatures.h:208
virtual void extractUnit(TensorDest acc, Unit *unit) override
Reimplement this in actual featurizers.
Definition: unitsfeatures.h:168
Rect boundingBox
Definition: unitsfeatures.h:34
UnitStatFeaturizer()
Definition: unitsfeatures.h:228
SubsampleMethod
Various methods for spatial subsampling.
Definition: features.h:218
virtual void extractUnit(TensorDest acc, Unit *unit) override
Reimplement this in actual featurizers.
Definition: unitsfeatures.h:217
Sparse featurizer for unit presence.
Definition: unitsfeatures.h:93
Rect2T< int > Rect
Definition: basetypes.h:309
Abstract base class for featurizing unit attributes in a sparse manner.
Definition: unitsfeatures.h:29
int unmapType(int mappedType) const
Definition: unitsfeatures.h:161
bool isNeutral
Definition: unitsinfo.h:55
std::function< bool(Unit *)> UnitFilter
Definition: unitsfeatures.h:30
Definition: unitsfeatures.h:224
virtual Data extract(State *state, UnitsInfo::Units const &units, Rect const &boundingBox=Rect())
Extract unit features for a given set of units.
Definition: unitsfeatures.cpp:48
virtual void extractUnit(TensorDest acc, Unit *) override
Reimplement this in actual featurizers.
Definition: unitsfeatures.h:101
Sparse featurizer for numeric unit types.
Definition: unitsfeatures.h:116
Sparse featurizer for unit flags.
Definition: unitsfeatures.h:207
CustomFeatureType type
Definition: unitsfeatures.h:51
torch::TensorAccessor< float, 1 > TensorDest
Definition: unitsfeatures.h:31
int mapType(int unitType) const
Definition: unitsfeatures.h:158
CustomFeatureType
Defines custom features.
Definition: features.h:87
Represents a collection of spatial feature data.
Definition: features.h:190
Represents a unit in the game.
Definition: unitsinfo.h:35
bool isEnemy
Definition: unitsinfo.h:54
virtual ~UnitAttributeFeaturizer()=default
GEN_SPARSE_UNIT_ATTRIBUTE_FEATURIZER(HP, health)
std::array< int, 234 > * itypemap_
Definition: unitsfeatures.h:179
Definition: unitsfeatures.h:33
tc::Unit unit
A copy of the torchcraft unit data.
Definition: unitsinfo.h:81
FeatureData toSpatialFeature(Data const &data, SubsampleMethod pooling=SubsampleMethod::Sum) const
Embeds the unit attribute data into a spatial feature.
Definition: unitsfeatures.cpp:110
bool isMine
Definition: unitsinfo.h:53
int unit
Definition: buildtype.h:37
Main namespace for bot-related code.
Definition: areainfo.cpp:17
std::array< int, 234 > * typemap_
Definition: unitsfeatures.h:178
UnitFlagsFeaturizer()
Definition: unitsfeatures.h:210
const BuildType * type
Definition: unitsinfo.h:56
void serialize(Archive &ar)
#units X nchannels
Definition: unitsfeatures.h:41
Sparse featurizer for unit types, defogger-style.
Definition: unitsfeatures.h:153
torch::Tensor data
#units X 2 (y, x)
Definition: unitsfeatures.h:38
virtual void extractUnit(TensorDest acc, Unit *unit) override
Reimplement this in actual featurizers.
Definition: unitsfeatures.h:131
std::vector< Unit * > Units
Definition: unitsinfo.h:296
uint64_t flags
Definition: frame.h:85
std::shared_ptr< BaseJitter > jitter
Optional jittering of unit positions.
Definition: unitsfeatures.h:47
A variant of UnitTypeDefoggerFeaturizer that stores the target type of morphing units.
Definition: unitsfeatures.h:188
std::string name
Definition: unitsfeatures.h:52
virtual void extractUnit(TensorDest acc, Unit *unit)=0
Reimplement this in actual featurizers.