mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
BattleAI: remove adjustPositions method as it gives more troubles than usefulness
This commit is contained in:
@@ -225,7 +225,7 @@ BattleAction BattleEvaluator::selectStackAction(const CStack * stack)
|
||||
}
|
||||
}
|
||||
|
||||
return BattleAction::makeDefend(stack);
|
||||
return stack->waited() ? BattleAction::makeDefend(stack) : BattleAction::makeWait(stack);
|
||||
}
|
||||
|
||||
uint64_t timeElapsed(std::chrono::time_point<std::chrono::high_resolution_clock> start)
|
||||
|
@@ -684,11 +684,6 @@ BattleScore BattleExchangeEvaluator::calculateExchange(
|
||||
for(auto hex : hexes)
|
||||
reachabilityMap[hex] = getOneTurnReachableUnits(turn, hex);
|
||||
|
||||
if(!ap.attack.shooting)
|
||||
{
|
||||
v.adjustPositions(melleeAttackers, ap, reachabilityMap);
|
||||
}
|
||||
|
||||
#if BATTLE_TRACE_LEVEL>=1
|
||||
logAi->trace("Exchange score: enemy: %2f, our -%2f", v.getScore().enemyDamageReduce, v.getScore().ourDamageReduce);
|
||||
#endif
|
||||
@@ -696,69 +691,6 @@ BattleScore BattleExchangeEvaluator::calculateExchange(
|
||||
return v.getScore();
|
||||
}
|
||||
|
||||
void BattleExchangeVariant::adjustPositions(
|
||||
std::vector<const battle::Unit*> attackers,
|
||||
const AttackPossibility & ap,
|
||||
std::map<BattleHex, battle::Units> & reachabilityMap)
|
||||
{
|
||||
auto hexes = ap.attack.defender->getSurroundingHexes();
|
||||
|
||||
boost::sort(attackers, [&](const battle::Unit * u1, const battle::Unit * u2) -> bool
|
||||
{
|
||||
if(attackerValue[u1->unitId()].isRetalitated && !attackerValue[u2->unitId()].isRetalitated)
|
||||
return true;
|
||||
|
||||
if(attackerValue[u2->unitId()].isRetalitated && !attackerValue[u1->unitId()].isRetalitated)
|
||||
return false;
|
||||
|
||||
return attackerValue[u1->unitId()].value > attackerValue[u2->unitId()].value;
|
||||
});
|
||||
|
||||
vstd::erase_if_present(hexes, ap.from);
|
||||
vstd::erase_if_present(hexes, ap.attack.attacker->occupiedHex(ap.attack.attackerPos));
|
||||
|
||||
float notRealizedDamage = 0;
|
||||
|
||||
for(auto unit : attackers)
|
||||
{
|
||||
if(unit->unitId() == ap.attack.attacker->unitId())
|
||||
continue;
|
||||
|
||||
if(!vstd::contains_if(hexes, [&](BattleHex h) -> bool
|
||||
{
|
||||
return vstd::contains(reachabilityMap[h], unit);
|
||||
}))
|
||||
{
|
||||
notRealizedDamage += attackerValue[unit->unitId()].value;
|
||||
continue;
|
||||
}
|
||||
|
||||
auto desiredPosition = vstd::minElementByFun(hexes, [&](BattleHex h) -> float
|
||||
{
|
||||
auto score = vstd::contains(reachabilityMap[h], unit)
|
||||
? reachabilityMap[h].size()
|
||||
: 0;
|
||||
|
||||
if(unit->doubleWide())
|
||||
{
|
||||
auto backHex = unit->occupiedHex(h);
|
||||
|
||||
if(vstd::contains(hexes, backHex))
|
||||
score += reachabilityMap[backHex].size();
|
||||
}
|
||||
|
||||
return score;
|
||||
});
|
||||
|
||||
hexes.erase(desiredPosition);
|
||||
}
|
||||
|
||||
if(notRealizedDamage > ap.attackValue() && notRealizedDamage > attackerValue[ap.attack.attacker->unitId()].value)
|
||||
{
|
||||
dpsScore = BattleScore(EvaluationResult::INEFFECTIVE_SCORE, 0);
|
||||
}
|
||||
}
|
||||
|
||||
bool BattleExchangeEvaluator::canBeHitThisTurn(const AttackPossibility & ap)
|
||||
{
|
||||
for(auto pos : ap.attack.attacker->getSurroundingHexes())
|
||||
|
@@ -106,11 +106,6 @@ public:
|
||||
|
||||
const BattleScore & getScore() const { return dpsScore; }
|
||||
|
||||
void adjustPositions(
|
||||
std::vector<const battle::Unit *> attackers,
|
||||
const AttackPossibility & ap,
|
||||
std::map<BattleHex, battle::Units> & reachabilityMap);
|
||||
|
||||
private:
|
||||
BattleScore dpsScore;
|
||||
std::map<uint32_t, AttackerValue> attackerValue;
|
||||
|
Reference in New Issue
Block a user