本文整理汇总了C++中bwapi::Unitset::find方法的典型用法代码示例。如果您正苦于以下问题:C++ Unitset::find方法的具体用法?C++ Unitset::find怎么用?C++ Unitset::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bwapi::Unitset
的用法示例。
在下文中一共展示了Unitset::find方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: edges
std::unordered_map<BWAPI::Unit, BWAPI::Unit> RangedManager::assignEnemy(const BWAPI::Unitset &meleeUnits, BWAPI::Unitset & meleeUnitTargets)
{
std::unordered_map<BWAPI::Unit, BWAPI::Unit> attacker2target;
std::vector<PairEdge> edges(meleeUnits.size()*meleeUnitTargets.size());
int top = 0;
for (auto &attacker : meleeUnits)
{
for (auto &target : meleeUnitTargets)
{
if (!target)
continue;
edges[top].attacker = attacker;
edges[top].target = target;
int groundWeaponRange = attacker->getType().groundWeapon().maxRange();
edges[top++].distance = -getRealPriority(attacker, target);
}
}
sort(edges.begin(), edges.end());
sort(edges.begin(), edges.end(), [](PairEdge a, PairEdge b)
{
return a.target->getID() <b.target->getID();
});
PairEdge dummy;
dummy.target = nullptr;
edges.push_back(dummy);
BWAPI::Unit p = nullptr;
int sum = 0;
for (auto idx = edges.begin(); idx!=edges.end(); idx++)
{
if (!idx->target)
continue;
double Health = (((double)idx->target->getHitPoints() + idx->target->getShields()));
if (idx->target->getType().size() == BWAPI::UnitSizeTypes::Small)
Health *= 2;
if (idx->target->getType().size() == BWAPI::UnitSizeTypes::Medium)
Health *= 1.5;
if (p != idx->target)
{
sum = 0;
p = idx->target;
}
else
{
sum++;
//assign at most 7 units attack
//BWAPI::Broodwar <<( idx->target->getHitPoints()+idx->target->getShields()) / idx->attacker->getType().groundWeapon().damageAmount() << std::endl;
if (sum>std::min(8, 1+(int)(Health / idx->attacker->getType().groundWeapon().damageAmount())))
{
idx->attacker = nullptr;
if (meleeUnitTargets.find(idx->target) != meleeUnitTargets.end())
meleeUnitTargets.erase(idx->target);
}
}
}
int t = 0;
for (bool halt=false; halt == false; halt = true)
{
halt= true;
auto tmpRangeStart = edges.begin();
auto maxRangeStart = tmpRangeStart, maxRangeEnd = tmpRangeStart;
double tmpsum = 0, tmpres = INT_MIN;
for (auto idx = edges.begin(); idx->target != nullptr; idx++)
{
if (attacker2target.find(idx->attacker) != attacker2target.end())
continue;
if (idx->target != (idx + 1)->target)
{
if (tmpsum > tmpres)
{
tmpres = tmpsum;
maxRangeStart = tmpRangeStart;
maxRangeEnd = idx + 1;
}
tmpsum = 0;
tmpRangeStart = idx + 1;
}
else
tmpsum += getRealPriority(idx->attacker, idx->target);
}
for (auto kdx = maxRangeStart; kdx < maxRangeEnd; kdx++)
{
if (attacker2target.find(kdx->attacker) != attacker2target.end())
continue;
attacker2target[kdx->attacker] = kdx->target;
halt = false;
}
t++;
}
return attacker2target;
}