14 namespace movefilters {
27 virtual bool blocking() = 0;
43 template <
typename T,
typename Container>
47 std::function<Container
const && (
Unit*)> getter,
49 std::function<
float(
Unit*,
Position const&, T)> scoreFunc,
51 bool blocking =
false)
52 : getter_(
std::move(getter)),
53 valid_(
std::move(valid)),
54 score_(
std::move(scoreFunc)),
56 blocking_(blocking) {}
59 VLOG(4) <<
"PositionFilter: in filter valid";
60 auto objects = getter_(agent);
61 VLOG(4) <<
"PositionFilter: in valid non empty set? size is: " 64 for (
auto obj : objects) {
65 if (!valid_(agent, pos, obj)) {
71 for (
auto obj : objects) {
72 if (valid_(agent, pos, obj)) {
78 LOG(DFATAL) <<
"MoveHelpers: incorrect position filter policy";
86 for (
auto obj : getter_(agent)) {
87 auto s = score_(agent, pos, obj);
95 for (
auto obj : getter_(agent)) {
96 auto s = score_(agent, pos, obj);
103 LOG(DFATAL) <<
"MoveHelpers: incorrect position filter policy";
113 std::function<Container const && (Unit*)>
getter_;
114 std::function<bool(Unit*, Position const&, T)>
valid_;
115 std::function<float(Unit*, Position const&, T)>
score_;
127 PPositionFilter base,
129 bool blocking =
false)
130 : base_(base), allFilters_(l), blocking_(blocking) {}
133 if (!base_->isValid(agent, pos)) {
136 for (
auto& filt : allFilters_) {
137 if (!filt->isValid(agent, pos)) {
145 return base_->score(agent, pos);
166 bool blocking =
false)
167 : allFilters_(l), policy_(policy), blocking_(blocking) {}
171 for (
auto& filt : allFilters_) {
172 if (!filt->isValid(agent, pos)) {
178 for (
auto& filt : allFilters_) {
179 if (filt->isValid(agent, pos)) {
185 LOG(ERROR) <<
"invalid moveFilter policy";
192 for (
auto& filt : allFilters_) {
193 auto score = filt->score(agent, pos);
194 if (score > max_score) {
201 for (
auto& filt : allFilters_) {
202 auto score = filt->score(agent, pos);
203 if (score < min_score) {
209 LOG(ERROR) <<
"invalid moveFilter policy";
231 std::vector<Position> storage_;
235 template <
typename T,
typename UnaryFunctionReturnsContainerTType>
237 UnaryFunctionReturnsContainerTType getter,
239 std::function<
float(
Unit*,
Position const&, T)> scoreFunc,
241 bool blocking =
false) {
242 auto filter = std::make_shared<
246 std::move(scoreFunc),
253 PPositionFilter base,
255 bool blocking =
false);
260 bool blocking =
false);
302 PPositionFilter
getCloserTo(std::vector<Position> coordinates);
318 std::vector<Unit*>
const& obstacles,
319 bool outOFBoundsInvalid);
324 PositionFilters
const& filters,
325 int moveLength = kMoveLength,
326 int nbPossibleMoves = kNumberPossibleMoves,
327 int stepSize = kMoveLOSStepSize,
328 bool outOfBoundsInvalid =
true);
334 template <
typename T>
342 PositionFilters
const& filters,
343 int moveLength = kMoveLength,
344 int nbPossibleMoves = kNumberPossibleMoves,
345 int stepSize = kMoveLOSStepSize,
346 bool outOfBoundsInvalid =
true);
351 PPositionFilter
const& filter,
352 int moveLength = kMoveLength,
353 int nbPossibleMoves = kNumberPossibleMoves,
354 int stepSize = kMoveLOSStepSize,
355 bool outOfBoundsInvalid =
true);
PPositionFilter fleeThreatening()
Definition: movefilters.cpp:172
Game state.
Definition: state.h:42
Position safeDirectionTo(State *state, Unit *unit, T tgt)
Definition: movefilters.cpp:280
bool dangerousAttack(Unit *unit, Unit *tgt)
Definition: movefilters.cpp:132
PPositionFilter avoidAttackers()
Definition: movefilters.cpp:184
std::vector< Unit * > & beingAttackedByEnemiesGetter(Unit *u)
Definition: movefilters.h:272
auto negDistanceScore(Unit *unit, Position const &pos, Unit *nmy)
Definition: movefilters.h:287
bool unitTouch(Unit *unit, Unit *v, int dirX, int dirY)
Definition: movefilters.cpp:39
Position safeMoveTo(State *state, Unit *unit, Position const &pos)
Definition: movefilters.cpp:307
PPositionFilter makePositionFilter(PPositionFilter base, PositionFilters l, bool blocking)
Definition: movefilters.cpp:15
This filter uses the score of the base filter, only of all subfilters return that the position is val...
Definition: movefilters.h:124
std::vector< Unit * > & unitsInSightRangeGetter(Unit *u)
Definition: movefilters.h:275
std::vector< Position > const & operator()(Unit *agent)
Definition: movefilters.h:226
Position pathMoveTo(State *state, Unit *unit, Position const &pos)
Definition: movefilters.cpp:324
float score(Unit *agent, Position const &pos) override
Definition: movefilters.h:189
bool isValid(Unit *agent, Position const &pos) override
Definition: movefilters.h:169
int constexpr kMoveLength
Definition: movefilters.h:307
PositionFilters allFilters_
Definition: movefilters.h:154
std::vector< Unit * > obstaclesInSightRange
Definition: unitsinfo.h:100
FuncPositionFilter(std::function< Container const &&(Unit *)> getter, std::function< bool(Unit *, Position const &, T)> valid, std::function< float(Unit *, Position const &, T)> scoreFunc, PositionFilterPolicy policy=PositionFilterPolicy::ACCEPT_IF_ALL, bool blocking=false)
Definition: movefilters.h:46
std::vector< Unit * > allyUnitsInSightRange
Definition: unitsinfo.h:103
bool blocking_
Definition: movefilters.h:117
UnionPositionFilter(PositionFilters l, PositionFilterPolicy policy=PositionFilterPolicy::ACCEPT_IF_ALL, bool blocking=false)
Definition: movefilters.h:163
double distanceTo(Vec2T const &other) const
Definition: basetypes.h:122
int constexpr kMinDistToTargetPos
Definition: movefilters.h:311
std::vector< PPositionFilter > PositionFilters
Definition: movefilters.h:31
int constexpr kTimeUpdateMove
Definition: movefilters.h:313
int constexpr kNumberPossibleMoves
Definition: movefilters.h:308
std::function< Container const &&(Unit *)> getter_
Definition: movefilters.h:113
ConstantGetter(std::vector< Position > values)
Definition: movefilters.h:225
std::vector< Unit * > enemyUnitsInSightRange
Definition: unitsinfo.h:102
int constexpr kMoveLOSStepSize
Definition: movefilters.h:310
PositionFilters allFilters_
Definition: movefilters.h:218
bool blocking() override
Definition: movefilters.h:213
PPositionFilter avoidThreatening()
Definition: movefilters.cpp:189
bool isValid(Unit *agent, Position const &pos) override
Definition: movefilters.h:132
bool isValid(Unit *agent, Position const &pos) override
Definition: movefilters.h:58
PositionFilterPolicy
Definition: movefilters.h:16
PPositionFilter getCloserTo(std::vector< Position > coordinates)
Definition: movefilters.cpp:204
bool blocking() override
Definition: movefilters.h:108
bool positionAvoids(Unit *unit, Position const &pos, Unit *nmy)
Definition: movefilters.cpp:74
bool moveIsPossible(State *state, Position const &pos, std::vector< Unit * > const &obstacles, bool outOfBoundsInvalid)
Definition: movefilters.cpp:262
std::shared_ptr< PositionFilter > PPositionFilter
Definition: movefilters.h:30
Represents a unit in the game.
Definition: unitsinfo.h:35
bool blocking_
Definition: movefilters.h:220
bool walkable(State *state, Position const &pos)
Definition: movefilters.cpp:257
std::vector< Unit * > & threateningEnemiesGetter(Unit *u)
Definition: movefilters.h:269
bool insideAnyUnit(Unit *unit, Position const &pos, std::vector< Unit * > units)
Definition: movefilters.cpp:68
Assigns positions a score and validity, based on some criteria.
Definition: movefilters.h:22
std::vector< Unit * > threateningEnemies
Definition: unitsinfo.h:93
auto distanceScore(Unit *unit, Position const &pos, Unit *nmy)
Definition: movefilters.h:290
std::function< float(Unit *, Position const &, T)> score_
Definition: movefilters.h:115
auto zeroScore(Unit *unit, Position const &pos, Unit *nmy)
Definition: movefilters.h:293
std::vector< std::vector< std::pair< float, Position > > > getValidMovePositions(State *state, Unit *unit, PositionFilters const &filters, int moveLength=kMoveLength, int nbPossibleMoves=kNumberPossibleMoves, int stepSize=kMoveLOSStepSize, bool outOfBoundsInvalid=true)
PositionFilterPolicy policy_
Definition: movefilters.h:116
PPositionFilter avoidEnemyUnitsInRange(float range)
Definition: movefilters.cpp:194
float constexpr kfInfty
Definition: basetypes.h:29
float score(Unit *agent, Position const &pos) override
Definition: movefilters.h:83
Definition: movefilters.h:223
bool insideSpecificUnit(Position const &pos, Unit *bldg, int margin)
Definition: movefilters.cpp:28
bool blocking_
Definition: movefilters.h:155
class to combine filters
Definition: movefilters.h:161
MultiPositionFilter(PPositionFilter base, PositionFilters l, bool blocking=false)
Definition: movefilters.h:126
Position smartMove(State *state, Unit *unit, PositionFilters const &filters, int moveLength, int nbPossibleMoves, int stepSize, bool outOfBoundsInvalid)
Definition: movefilters.cpp:355
PPositionFilter fleeAttackers()
Definition: movefilters.cpp:160
PPositionFilter base_
Definition: movefilters.h:153
Main namespace for bot-related code.
Definition: areainfo.cpp:17
float score(Unit *agent, Position const &pos) override
Definition: movefilters.h:144
bool blocking() override
Definition: movefilters.h:148
std::vector< Unit * > unitsInSightRange
Definition: unitsinfo.h:98
int constexpr kMinMoveLength
Definition: movefilters.h:309
std::vector< Unit * > beingAttackedByEnemies
Definition: unitsinfo.h:95
std::vector< Unit * > & enemyUnitsInSightRangeGetter(Unit *u)
Definition: movefilters.h:281
PositionFilterPolicy policy_
Definition: movefilters.h:219
std::vector< Unit * > & obstaclesInSightRangeGetter(Unit *u)
Definition: movefilters.h:278
std::vector< Unit * > & allyUnitsInSightRangeGetter(Unit *u)
Definition: movefilters.h:284
std::function< bool(Unit *, Position const &, T)> valid_
Definition: movefilters.h:114
Input:
Definition: movefilters.h:44