13 #include "tilesinfo.h" 17 DECLARE_uint64(tactics_fight_or_flee_interval);
39 this->
units() = std::move(units);
48 virtual const char*
getName()
const override {
56 Unit* targetUnit =
nullptr;
59 std::shared_ptr<TacticsTask>
task;
60 bool hasEnoughUnits =
false;
61 bool hasEnemyGroundUnits =
false;
62 bool hasEnemyAirUnits =
false;
63 bool hasEnemyBuildings =
false;
64 bool hasEnemyCloakedUnits =
false;
65 bool hasEnemyTanks =
false;
66 bool hasEnemyReavers =
false;
67 bool hasEnemyBunkers =
false;
68 bool hasEnemyWorkers =
false;
69 bool hasEnemyAntiGround =
false;
70 bool hasEnemyAntiAir =
false;
71 bool hasEnemyStaticDefence =
false;
72 bool enemiesAreAttacking =
false;
73 bool enemiesInOurBase =
false;
74 bool isAggressiveGroup =
true;
76 bool searchAndDestroy =
false;
77 bool isIdleGroup =
false;
78 bool isScoutGroup =
false;
79 bool enemyIsOnlyWorkers =
true;
85 Unit* nearestEnemy =
nullptr;
91 bool groundFight =
true;
101 float insideGroupDistance_ = 4 * 16;
102 uint8_t visitNumber_ = 0;
103 std::vector<uint8_t> tileVisitTracker_ =
105 std::vector<uint8_t> tileSpotTakenTracker_ =
107 std::vector<TacticsMapNode> nodeInsideGroupTracker_ =
108 std::vector<TacticsMapNode>(
110 std::vector<TacticsGroup*> nodeGroupEdgeTracker_ = std::vector<TacticsGroup*>(
117 void createTacticsGroups(
State* state, std::vector<uint8_t>& inBaseArea);
118 void collectMapNodesCoveredByGroups(
State* state);
121 std::unordered_set<Unit*>& wasInAGroup,
122 std::vector<Unit*> leftoverWorkers,
123 std::vector<std::shared_ptr<Task>>& tasks);
129 std::unordered_map<Unit*, int>& nmyInStaticDefenceRange,
130 std::unordered_map<Unit*, int>& nmyAlmostInStaticDefenceRange);
131 Unit* getBestEnemyTarget(
135 std::unordered_map<Unit*, int>& meleeTargetCount,
136 std::unordered_map<Unit*, int>& lastTargetInRange,
137 bool& anySpiderMinesNearby);
142 idleGroupTargetPos(
State* state,
Unit* u, std::vector<uint8_t>& inBaseArea);
148 std::unordered_map<
Unit*, std::pair<int, Position>>& scoutTarget,
149 std::ranlux24& rngEngine);
150 Position searchAndDestroyGroupTargetPos(
153 std::unordered_map<
Unit*, std::pair<int, Position>>&
154 searchAndDestroyTarget,
155 std::ranlux24& rngEngine);
159 void addEnemyUnitToGroup(
163 std::vector<uint8_t>
const& inBaseArea);
164 void assignUnitsBasedOnPreviousAssignments(
166 std::unordered_set<Unit*>& wasInAGroup,
167 std::vector<std::shared_ptr<Task>>& tasks);
168 void collectAvailableUnits(
State* state, std::vector<Unit*>& availableUnits);
169 void assignScoutingUnits(
State* state, std::vector<Unit*>& availableUnits);
170 bool aggressiveUnit(
State* state,
Unit* unit);
172 void assignNecessaryUnits(
State* state, std::vector<Unit*>& availableUnits);
173 void assignDetectors(std::vector<Unit*>& availableUnits);
174 void assignLeftovers(
176 std::vector<Unit*>& availableUnits,
177 std::vector<Unit*>& leftoverWorkers);
181 void prepareCombatSimulationData(
184 std::vector<Unit*>& nearbyAllies,
185 std::unordered_set<Unit*>& nearbyEnemies,
186 std::unordered_map<Unit*, int>& nmyInStaticDefenseRange,
187 std::unordered_map<Unit*, int>& nmyAlmostInStaticDefenseRange);
188 std::pair<double, double> combatSimCalculateFightScoreMod(
191 std::vector<Unit*>& nearbyAllies,
192 std::unordered_set<Unit*>& nearbyEnemies,
193 std::unordered_map<Unit*, int>& nmyInStaticDefenseRange);
196 int getRandomCoord(
int range, std::ranlux24& rngEngine);
216 virtual void step(
State* s)
override;
217 virtual void onGameEnd(
State* s)
override;
224 virtual void process(
State* state,
int srcUpcId);
233 std::vector<Unit*>& leftoverWorkers,
234 std::unordered_set<Unit*>& wasInAGroup);
243 void distributeLeftoverWorkers(
244 std::unordered_set<Unit*>& unitSet,
245 std::vector<Unit*>& leftoverWorkers,
246 std::unordered_set<Unit*>& wasInAGroup);
250 void processNonFightFleeGroup(
254 std::vector<Unit*>& leftoverWorkers,
255 std::unordered_set<Unit*>& wasInAGroup);
264 std::pair<double, double> distributeFightFlee(
268 std::vector<Unit*>& fightUnits,
269 std::vector<Unit*>& fleeUnits);
278 std::vector<Unit*>& fightUnits,
279 std::vector<Unit*>& fleeUnits,
280 std::vector<Unit*>& leftoverWorkers,
281 std::unordered_set<Unit*>& wasInAGroup);
283 std::vector<uint8_t> inBaseArea_ =
287 std::vector<uint16_t> fleeScore_ =
293 std::ranlux24 rngEngine_{42};
304 virtual bool alwaysFight()
override {
Game state.
Definition: state.h:42
int FrameNum
Definition: basetypes.h:22
std::list< TacticsGroup > groups_
Definition: tactics.h:114
std::unordered_map< Unit *, std::pair< int, Position > > searchAndDestroyTarget_
Definition: tactics.h:291
TacticsTask(int upcId)
Definition: tactics.h:25
UpcId upcId() const
UPC id in Blackboard that caused this Task to be spawned.
Definition: task.h:90
std::unordered_set< Unit * > const & units() const
A set of units occupied performing this task.
Definition: task.h:94
std::vector< Unit * > myUnits
Definition: tactics.h:43
void updateTasksByUnit(Task *task)
Updates the taskByUnit mapping, should be called after setUnits on a task.
Definition: blackboard.cpp:328
virtual const char * getName() const override
A name for this task, for debugging purposes.
Definition: tactics.h:48
std::vector< Unit * > enemyUnits
Definition: tactics.h:54
virtual void cancel(State *state) override
Definition: tactics.h:31
Position averagePos
Definition: tactics.h:58
virtual void removeDeadOrReassignedUnits(State *state)
Remove units that have been assigned to another task and units that have died.
Definition: task.cpp:36
The primary way for modules to publish their activity.
Definition: task.h:50
virtual void cancel(State *)
Definition: task.cpp:18
std::unordered_map< Unit *, std::pair< int, Position > > scoutTarget_
Definition: tactics.h:292
replayer::Unit Unit
Definition: state.h:36
Position targetPos
Definition: tactics.h:57
Represents a unit in the game.
Definition: unitsinfo.h:35
static const unsigned tilesWidth
Definition: tilesinfo.h:98
std::unordered_map< Unit *, int > lastTargetInRange_
Definition: tactics.h:295
Position averagePos
Definition: tactics.h:45
static const unsigned tilesHeight
Definition: tilesinfo.h:99
int srcUpcId_
Definition: tactics.h:96
std::unordered_map< Unit *, TacticsGroup * > softAssignedUnits_
Definition: tactics.h:113
Blackboard * board() const
Definition: state.h:99
virtual void update(State *state) override
Definition: tactics.h:27
Represents a tile on the map.
Definition: tilesinfo.h:29
std::vector< Unit * > myUnits
Definition: tactics.h:55
Definition: tactics.h:303
std::shared_ptr< TacticsTask > task
Definition: tactics.h:59
The Tactics module decides where on the map to allocate combat units.
Definition: tactics.h:214
Main namespace for bot-related code.
Definition: areainfo.cpp:17
std::unordered_map< Unit *, TacticsGroup * > hardAssignedUnits_
Definition: tactics.h:112
int UpcId
Definition: basetypes.h:23
Position targetPos
Definition: tactics.h:44
Interface for bot modules.
Definition: module.h:30
virtual bool alwaysFight()
Definition: tactics.h:298
bool isFighting
Definition: tactics.h:46
std::unordered_map< Unit *, int > lastMove_
Definition: tactics.h:296
void setUnits(State *state, std::unordered_set< Unit * > units)
Definition: tactics.h:38