mirror of
https://github.com/nolen777/eagle0.git
synced 2026-07-29 07:35:42 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5345d9f8fb | ||
|
|
2006f8ef62 | ||
|
|
c8023d0533 | ||
|
|
f6088729b1 |
@@ -222,20 +222,9 @@ auto IsDeterministic(const CommandType type) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
static auto RecursiveAttackerMultiplierForTargetDistance(
|
||||
static auto FlattenedAttackerMultiplierForTargetDistance(
|
||||
const Unit *attackingUnit,
|
||||
vector<TargetAndAttackLocations>::const_iterator &priorityListNext,
|
||||
const vector<TargetAndAttackLocations>::const_iterator &priorityListEnd,
|
||||
const vector<const Unit *> &occupants,
|
||||
const HexMap *map,
|
||||
const BattalionTypeSPtr &battType,
|
||||
const std::shared_ptr<ActionPointDistances> ¬BravingApd,
|
||||
const std::shared_ptr<ActionPointDistances> &bravingApd,
|
||||
bool isLateGame) -> double;
|
||||
|
||||
static auto RecursiveAttackerMultiplierForTargetDistance(
|
||||
const Unit *attackingUnit,
|
||||
vector<TargetAndAttackLocations>::const_iterator &priorityListNext,
|
||||
vector<TargetAndAttackLocations>::const_iterator priorityListNext,
|
||||
const vector<TargetAndAttackLocations>::const_iterator &priorityListEnd,
|
||||
const vector<const Unit *> &occupants,
|
||||
const HexMap *map,
|
||||
@@ -243,34 +232,33 @@ static auto RecursiveAttackerMultiplierForTargetDistance(
|
||||
const std::shared_ptr<ActionPointDistances> ¬BravingApd,
|
||||
const std::shared_ptr<ActionPointDistances> &bravingApd,
|
||||
const bool isLateGame) -> double {
|
||||
if (priorityListNext == priorityListEnd) return 1.0;
|
||||
double multiplier = 1.0;
|
||||
|
||||
const auto &[target, attackLocations] = *priorityListNext;
|
||||
const Coords &topPriorityTarget = target;
|
||||
// Iteratively process priority list instead of recursion
|
||||
while (priorityListNext != priorityListEnd) {
|
||||
const auto &[target, attackLocations] = *priorityListNext;
|
||||
const Coords &topPriorityTarget = target;
|
||||
|
||||
// If the target is unoccupied or is occupied by this player, give the maximum multiplier, but
|
||||
// also add the bonus for the next up in the priority list
|
||||
if (const Unit *occupant = occupants
|
||||
// Check if target is unoccupied or occupied by the same player
|
||||
const Unit *occupant = occupants
|
||||
[topPriorityTarget.row() * map->column_count() + topPriorityTarget.column()];
|
||||
!occupant || occupant->player_id() == attackingUnit->player_id()) {
|
||||
return kMaxProximityBuf + RecursiveAttackerMultiplierForTargetDistance(
|
||||
attackingUnit,
|
||||
++priorityListNext,
|
||||
priorityListEnd,
|
||||
occupants,
|
||||
map,
|
||||
battType,
|
||||
notBravingApd,
|
||||
bravingApd,
|
||||
isLateGame);
|
||||
|
||||
if (!occupant || occupant->player_id() == attackingUnit->player_id()) {
|
||||
// Add maximum proximity buffer and continue to next target
|
||||
multiplier += kMaxProximityBuf;
|
||||
++priorityListNext;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Found first occupied enemy target - calculate distance-based multiplier
|
||||
const DIST_T distance =
|
||||
EffectiveDistance(attackingUnit, notBravingApd, bravingApd, attackLocations);
|
||||
|
||||
multiplier *= kMaxProximityBuf / (1 + distance / kDistanceDebufRatio);
|
||||
break;
|
||||
}
|
||||
|
||||
// Use optimized EffectiveDistance with pre-computed ActionPointDistances
|
||||
// attackLocations is already the CoordsSet of attack locations for this target
|
||||
const DIST_T distance =
|
||||
EffectiveDistance(attackingUnit, notBravingApd, bravingApd, attackLocations);
|
||||
|
||||
return kMaxProximityBuf / (1 + distance / kDistanceDebufRatio);
|
||||
return multiplier;
|
||||
}
|
||||
|
||||
// Overload that accepts pre-computed ActionPointDistances
|
||||
@@ -284,7 +272,7 @@ auto AttackerMultiplierForTargetDistance(
|
||||
const std::shared_ptr<ActionPointDistances> &bravingApd,
|
||||
const bool isLateGame) -> double {
|
||||
auto iter = begin(priorityList);
|
||||
return RecursiveAttackerMultiplierForTargetDistance(
|
||||
return FlattenedAttackerMultiplierForTargetDistance(
|
||||
attackingUnit,
|
||||
iter,
|
||||
end(priorityList),
|
||||
@@ -296,6 +284,34 @@ auto AttackerMultiplierForTargetDistance(
|
||||
isLateGame);
|
||||
}
|
||||
|
||||
// Flattened (non-recursive) version for better performance
|
||||
auto FlattenedAttackerMultiplierForTargetDistance(
|
||||
const Unit *attackingUnit,
|
||||
const vector<TargetAndAttackLocations> &priorityList,
|
||||
const vector<const Unit *> &occupants,
|
||||
const HexMap *map,
|
||||
const std::shared_ptr<ActionPointDistances> ¬BravingApd,
|
||||
const std::shared_ptr<ActionPointDistances> &bravingApd,
|
||||
const bool isLateGame) -> double {
|
||||
double totalMultiplier = 0.0;
|
||||
|
||||
for (const auto &[target, attackLocations] : priorityList) {
|
||||
// If the target is unoccupied or is occupied by this player, give the maximum multiplier
|
||||
if (const Unit *occupant = occupants[target.row() * map->column_count() + target.column()];
|
||||
!occupant || occupant->player_id() == attackingUnit->player_id()) {
|
||||
totalMultiplier += kMaxProximityBuf;
|
||||
} else {
|
||||
// Use optimized EffectiveDistance with pre-computed ActionPointDistances
|
||||
const DIST_T distance =
|
||||
EffectiveDistance(attackingUnit, notBravingApd, bravingApd, attackLocations);
|
||||
totalMultiplier += kMaxProximityBuf / (1 + distance / kDistanceDebufRatio);
|
||||
break; // Stop at first occupied target to match recursive behavior
|
||||
}
|
||||
}
|
||||
|
||||
return totalMultiplier == 0.0 ? 1.0 : totalMultiplier;
|
||||
}
|
||||
|
||||
auto AttackerUnitsScore(
|
||||
const GameState *gameState,
|
||||
int roundsRemaining,
|
||||
@@ -382,12 +398,11 @@ auto AttackerUnitsScore(
|
||||
// they are to being able to attack it
|
||||
double distanceMultiplier = priorityList == end(attackerTargetPriorities)
|
||||
? 1.0
|
||||
: AttackerMultiplierForTargetDistance(
|
||||
: FlattenedAttackerMultiplierForTargetDistance(
|
||||
unit,
|
||||
priorityList->priorityOrder,
|
||||
occupants,
|
||||
gameState->hex_map(),
|
||||
cachedAPDs.GetBattalionType(battTypeId),
|
||||
cachedAPDs.GetRegular(battTypeId),
|
||||
cachedAPDs.GetBraving(battTypeId),
|
||||
isLateGame);
|
||||
|
||||
Reference in New Issue
Block a user