public void ExecuteBestActionForUnitAgent(List <UnitAgent> squad) { if (SCUnit.isVisible() && GoalUnitToAttack != null) //Always remember to check if the unit is visible, before Moving it. { SubGoalPosition = CalculateNewSubGoalPosition(squad, GoalUnitToAttack); if (SCUnit.getGroundWeaponCooldown() != 0) { SCUnit.rightClick(SubGoalPosition); } else { SCUnit.attack(SubGoalPosition); } } }
/// <summary> /// Calculate the potential of the specified field/position. /// </summary> /// <param name="squad"></param> /// <param name="enemy"></param> /// <param name="field"></param> /// <returns></returns> public double CalculatePotentialField(List <UnitAgent> squad, Unit enemy, Position field) { double pVal = 0; //DO NOT UPDATE WITH EVOLUTIONARY ALGORITHM const double forceNeutralUnitsRepulsion = 200; // 0 - 1000 //REMEMBER TO SET TO A POSITIVE NUMBER. const double forceStepNeutralUnitsRepulsion = 1.2; // 0 - 10 int rangeNeutralUnitsRepulsion = 8; //0-512 // /////////////////////////////////////////// double distance = enemy.getDistance(field); if (SCUnit.getGroundWeaponCooldown() == 0) //If the weapon is ready to fire, PFMaxShootingDistanceAttraction is activated { pVal += PFMaxShootingDistanceAttraction(distance, enemy, OptimizedProperties.ForceMSD, OptimizedProperties.ForceStepMSD); //, MSDDiffDivValue); } else if (SCMath.GetRange(SCUnit) > 1) //Else If Weapon is ready to fire and AttackRange is bigger than 1, FLEE/RETREAT until weapon is ready to fire again. { pVal += PFWeaponCoolDownRepulsion(field, distance, enemy, OptimizedProperties.ForceWeaponCoolDownRepulsion, OptimizedProperties.ForceStepWeaponCoolDownRepulsion, OptimizedProperties.RangeWeaponCooldownRepulsion); } //Squad attraction if (squad.Count > 2) { pVal += PFSquadAttraction(squad, field, OptimizedProperties.ForceSquadAttraction, OptimizedProperties.ForceStepSquadAttraction, OptimizedProperties.RangePercentageSquadAttraction); } //Center of the map attraction (NEGATES the MSD) pVal += PFMapCenterAttraction(field, OptimizedProperties.ForceMapCenterAttraction, OptimizedProperties.ForceStepMapCenterAttraction, OptimizedProperties.RangePecentageMapCenterAttraction); //Map edge repulsion (NEGATES the MSD) pVal += SCMath.CalculateMapEdgeRepulsion(field, OptimizedProperties.ForceMapEdgeRepulsion, OptimizedProperties.ForceStepMapEdgeRepulsion, OptimizedProperties.RangeMapEdgeRepulsion); //Own Unit Repulsion pVal += PFOwnUnitsRepulsion(squad, field, OptimizedProperties.ForceOwnUnitsRepulsion, OptimizedProperties.ForceStepOwnUnitsRepulsion, OptimizedProperties.RangeOwnUnitsRepulsion); //Enemy Unit Repulsion pVal += PFEnemyUnitsRepulsion(field, OptimizedProperties.ForceEnemyUnitsRepulsion, OptimizedProperties.ForceStepEnemyUnitsRepulsion); //, rangeEnemyUnitsRepulsion); //Neutral Unit Repulsion pVal += PFNeutralUnitsRepulsion(field, forceNeutralUnitsRepulsion, forceStepNeutralUnitsRepulsion, rangeNeutralUnitsRepulsion); return(pVal); }