Package megamek.client.bot.princess
Class InfantryCombatHelper
java.lang.Object
megamek.client.bot.princess.InfantryCombatHelper
Helper class for Princess AI infantry vs infantry combat decisions. Provides calculations and decision logic for
initiating, reinforcing, and withdrawing from building/vessel interior combat using the MarinePointsScore system.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcalculateAttackerMPS(Entity entity, Entity building) Calculate the Marine Points Score for an attacking unit.static intcalculateEnemyMPS(Game game, Entity target, Entity attacker) Calculate total enemy defender MPS in a hex.static doublecalculateInitiationThreshold(double bravery) Calculate initiation threshold based on bravery.static doublecalculateMPSRatio(int attackerMPS, int defenderMPS) Calculate MPS ratio (attacker / defender).static doublecalculateReinforcementTargetRatio(double initiationThreshold, double hyperAggression) Calculate reinforcement target ratio based on aggression.static doublecalculateWithdrawalThreshold(double initiationThreshold) Calculate withdrawal threshold.static intestimateCrewDefenders(Entity target) Estimate crew defenders (50% of total crew).static EntityfindBestReinforcement(List<Entity> candidates, Entity target) Deprecated, for removal: This API element is subject to removal in a future version.getEnemyInfantryInHex(Game game, Coords coords, int ownerId) Get all enemy infantry in a hex.static booleanshouldInitiateCombat(Entity attacker, Entity target, Game game, BehaviorSettings behavior) Determine if Princess should initiate infantry combat.static booleanshouldReinforce(Entity reinforcement, int targetId, Game game, BehaviorSettings behavior) Determine if Princess should reinforce existing infantry combat.static booleanshouldWithdraw(Entity entity, int targetId, Game game, BehaviorSettings behavior) Determine if Princess should withdraw from infantry combat.
-
Constructor Details
-
InfantryCombatHelper
public InfantryCombatHelper()
-
-
Method Details
-
calculateAttackerMPS
Calculate the Marine Points Score for an attacking unit.- Parameters:
entity- The attacking entity (must be Infantry)building- The target building/vessel- Returns:
- MPS value for the attacker
-
calculateEnemyMPS
Calculate total enemy defender MPS in a hex. Includes all enemy infantry + 50% of crew as potential defenders.- Parameters:
game- The current gametarget- The building/vessel being defendedattacker- The attacking entity- Returns:
- Total estimated defender MPS
-
calculateMPSRatio
public static double calculateMPSRatio(int attackerMPS, int defenderMPS) Calculate MPS ratio (attacker / defender).- Parameters:
attackerMPS- Attacker's MPSdefenderMPS- Defender's MPS- Returns:
- Ratio, or 0 if defender MPS is 0
-
calculateInitiationThreshold
public static double calculateInitiationThreshold(double bravery) Calculate initiation threshold based on bravery. Formula: 2.0 - (bravery / 3.0) * 0.5- Low bravery (0.1): ~2.0 (needs 2:1 odds) - Average bravery (1.5): ~1.75 (needs 7:4 odds) - High bravery (3.0): 1.5 (needs 3:2 odds)
- Parameters:
bravery- Bravery value from BehaviorSettings (0.1 to 3.0)- Returns:
- MPS ratio threshold required to initiate
-
calculateReinforcementTargetRatio
public static double calculateReinforcementTargetRatio(double initiationThreshold, double hyperAggression) Calculate reinforcement target ratio based on aggression. Formula: initiationThreshold + (hyperAggression / 10.0)Princess will reinforce to maintain ratio above this target.
- Parameters:
initiationThreshold- The threshold used to initiate combathyperAggression- HyperAggression value from BehaviorSettings (0.25 to 500)- Returns:
- Target MPS ratio to maintain via reinforcement
-
calculateWithdrawalThreshold
public static double calculateWithdrawalThreshold(double initiationThreshold) Calculate withdrawal threshold. Formula: initiationThreshold * 0.75Provides hysteresis - won't withdraw until significantly worse than initiation threshold.
- Parameters:
initiationThreshold- The threshold used to initiate combat- Returns:
- MPS ratio threshold below which to withdraw
-
shouldInitiateCombat
public static boolean shouldInitiateCombat(Entity attacker, Entity target, Game game, BehaviorSettings behavior) Determine if Princess should initiate infantry combat.- Parameters:
attacker- The potential attacking infantrytarget- The target building/vesselgame- The current gamebehavior- Princess's behavior settings- Returns:
- true if should initiate combat
-
shouldReinforce
public static boolean shouldReinforce(Entity reinforcement, int targetId, Game game, BehaviorSettings behavior) Determine if Princess should reinforce existing infantry combat.- Parameters:
reinforcement- The potential reinforcement infantrytargetId- The building/vessel ID where combat is happeninggame- The current gamebehavior- Princess's behavior settings- Returns:
- true if should send reinforcement
-
shouldWithdraw
public static boolean shouldWithdraw(Entity entity, int targetId, Game game, BehaviorSettings behavior) Determine if Princess should withdraw from infantry combat.- Parameters:
entity- The infantry unit in combattargetId- The building/vessel IDgame- The current gamebehavior- Princess's behavior settings- Returns:
- true if should withdraw
-
getEnemyInfantryInHex
Get all enemy infantry in a hex.- Parameters:
game- The current gamecoords- The coordinates to checkownerId- The owner ID of the attacking player- Returns:
- List of enemy infantry entities
-
estimateCrewDefenders
Estimate crew defenders (50% of total crew). Uses 50% of the entity's crew size as potential defenders.- Parameters:
target- The target building/vessel- Returns:
- Estimated number of crew defenders
-
findBestReinforcement
@Deprecated(since="0.51.0", forRemoval=true) public static Entity findBestReinforcement(List<Entity> candidates, Entity target) Deprecated, for removal: This API element is subject to removal in a future version.Find the best infantry unit to send as reinforcement. Priority: MPS/mass ratio, proximity, availability.- Parameters:
candidates- List of candidate unitstarget- The target building/vessel- Returns:
- Best reinforcement unit, or null if none suitable
-