public UnitAgent(Unit myUnit, UnitAgentOptimizedProperties opProp) { MyUnit = myUnit; OptimizedProperties = opProp; LeadingStatus = LeadingStatusEnum.None; EmotionalMode = EmotionalModeEnum.None; HealthLevelOk = 60; //Health + armor UnitAgentTypeName = "Unit_Agent"; }
public Position CalculateNewSubGoalPosition(List<UnitAgent> squad, Unit closestEnemyUnit) { int currentX = MyUnit.Position.X; int currentY = MyUnit.Position.Y; List<Position> surroundingPositions = MyMath.GetPossibleSurroundingPositionsRotation(currentX, currentY, 48, 35); double currentPotentialFieldValue = -1000; double bestPotentialFieldValue = -1000; Position bestPosition = MyUnit.Position; foreach (Position possibleNextPosition in surroundingPositions) { currentPotentialFieldValue = CalculatePotentialField(squad, closestEnemyUnit, possibleNextPosition); if (currentPotentialFieldValue > bestPotentialFieldValue) { bestPotentialFieldValue = currentPotentialFieldValue; bestPosition = possibleNextPosition; } } return bestPosition; }
/// <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.GetDistanceToPosition(field); if (MyUnit.WeaponGroundCooldown == 0) //If the weapon is ready to fire, PFMaxShootingDistanceAttraction is activated pVal += PFMaxShootingDistanceAttraction(distance, enemy, OptimizedProperties.ForceMSD, OptimizedProperties.ForceStepMSD);//, MSDDiffDivValue); else if (MyUnit.UnitType.AttackRange > 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 += MyMath.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; }
public static UnitAgent ConvertUnitToUnitAgent(Unit unit) { UnitAgent unitAgent; switch (unit.UnitTypeEnum) { case UnitTypes.Terran_SCV: unitAgent = new Terran_SCV_Agent(unit, GetOptimizedValuesToUnitAgent(unit.UnitTypeEnum.ToString())); break; case UnitTypes.Terran_Marine: unitAgent = new Terran_Marine_Agent(unit, GetOptimizedValuesToUnitAgent(unit.UnitTypeEnum.ToString())); break; case UnitTypes.Terran_Firebat: unitAgent = new Terran_Firebat_Agent(unit, GetOptimizedValuesToUnitAgent(unit.UnitTypeEnum.ToString())); break; case UnitTypes.Terran_Medic: unitAgent = new Terran_Medic_Agent(unit, GetOptimizedValuesToUnitAgent(unit.UnitTypeEnum.ToString())); break; case UnitTypes.Terran_Goliath: unitAgent = new Terran_Goliath_Agent(unit, GetOptimizedValuesToUnitAgent(unit.UnitTypeEnum.ToString())); break; case UnitTypes.Terran_Vulture: unitAgent = new Terran_Vulture_Agent(unit, GetOptimizedValuesToUnitAgent(unit.UnitTypeEnum.ToString())); break; case UnitTypes.Terran_TankTurretTankMode: case UnitTypes.Terran_SiegeTankSiegeTurret: case UnitTypes.Terran_SiegeTankTankMode: case UnitTypes.Terran_SiegeTankSiegeMode: unitAgent = new Terran_SiegeTank_Agent(unit, GetOptimizedValuesToUnitAgent(unit.UnitTypeEnum.ToString())); break; default: unitAgent = new UnitAgent(unit, GetOptimizedValuesToUnitAgent(unit.UnitTypeEnum.ToString())); break; } unitAgent.EmotionalMode = UnitAgent.EmotionalModeEnum.Exploration; return unitAgent; }
/// <summary> /// Orders the unit to use a tech requiring a unit target (ex: Irradiate). Returns true if it is a valid tech. /// </summary> /// <param name="techType"></param> /// <param name="unitTarget"></param> /// <returns></returns> public bool DoUseTech(TechTypes techType, Unit unitTarget) { return this.BwapiObject.useTech(new SWIG.BWAPI.TechType((int)techType), unitTarget.BwapiObject); }
/// <summary> /// Returns true if the given unit can upgrade the given upgrade type and there is enough resources required to upgrade. /// </summary> /// <param name="unitWhereToUpgrade"></param> /// <param name="upgradeType"></param> /// <returns></returns> public static bool CanUpgrade(Unit unitWhereToUpgrade, UpgradeType upgradeType) { return SWIG.BWAPI.bwapi.Broodwar.canUpgrade(unitWhereToUpgrade.BwapiObject, upgradeType.BwapiObject); }
/// <summary> /// Orders the unit to repair the specified unit. Only Terran SCVs can be ordered to repair, /// and the target must be a mechanical Terran unit or building. /// See also: IsRepairing. /// </summary> /// <param name="unitTarget"></param> /// <returns></returns> public bool DoRepair(Unit unitTarget) { return this.BwapiObject.repair(unitTarget.BwapiObject); }
/// <summary> /// Orders the unit to set its rally position to the specified unit. /// See also: RallyPosition, RallyUnit. /// </summary> /// <param name="unitTarget"></param> /// <returns></returns> public bool DoSetRallyPoint(Unit unitTarget) { return this.BwapiObject.setRallyPoint(unitTarget.BwapiObject); }
public static void OnUnitEvade(Unit unit) {}
public static void OnUnitRenegade(Unit unit) { //Util.Logger.Instance.Log("unit renegade: " + unit.UnitTypeEnum.ToString()); }
public static void OnUnitDestroy(Unit unit) { if (unit.IsMine) RemoveDeadUnitFromList(unit); }
/// <summary> /// Checks if the current unit's health level is ok. /// </summary> /// <returns>True if the current unit's health level is ok (health and shield level together is over 60).</returns> public Boolean IsHealthLevelOk(Unit unit) { int health = unit.HitPoints + unit.Shields; Boolean lowHealth = true; if (health < LastHealth) lowHealth = health >= HealthLevelOk; LastHealth = health; return lowHealth; }
/// <summary> /// Tells if the type of the specified own unit can be attacked by the specified enemy unitType. /// Inspiration from: BTHAI StarCraft bot ver. 1.00 /// </summary> /// <param name="ownUnit"></param> /// <param name="enemyUnit"></param> /// <returns>True if own unit can be attacked by the enemy unit</returns> public Boolean CanBeAttacked(Unit ownUnit, Unit enemyUnit) { UnitType ownUnitType = ownUnit.UnitType; UnitType enemyUnitType = enemyUnit.UnitType; if (ownUnitType.IsFlyer) { //Can enemy unit attack air units. if (enemyUnitType.WeaponGround.CanAttackAir) return true; if (enemyUnitType.WeaponAir.CanAttackAir) return true; } else { //Can enemy unit attack ground units. if (enemyUnitType.WeaponGround.CanAttackGround) return true; if (enemyUnitType.WeaponAir.CanAttackGround) return true; } return false; }
/// <summary> /// Calculate the potential value of the field that the current military unit can go to in the next frame, while the unit's weapon has it's cooldown period. /// Weapon cooldown happens each time the weapon is reloading. /// Some weapons are very effective, but recharges very slowly. It may therefore be a good tactic to flee when the weapon is in cool down, and thereby avoid being hit. /// </summary> /// <param name="field"></param> /// <param name="enemy"></param> /// <param name="distanceToEnemy"></param> /// <param name="force"></param> /// <param name="forceStep"></param> /// <param name="range"></param> /// <returns></returns> public double PFWeaponCoolDownRepulsion(Position field, double distanceToEnemy, Unit enemy, double force, double forceStep, int range) { if (enemy.IsVisible && IsInEnemyUnitsRange(field, range)) return MyMath.CalculateRepulsiveMagnitude(force, forceStep, distanceToEnemy, true); return 0; }
/// <summary> /// Calculates the potential value of the field that the current military unit can go to in the next frame, while the unit's weapon are ready to fire. /// The unit's Max Shooting Distance (MSD) will be the optimal place to be, because all enemy units with a shorter MSD then can't harm your unit, unless they move fastest. /// </summary> /// <param name="distanceToEnemy"></param> /// <param name="enemyUnit"></param> /// <param name="forceToOwnMSD"></param> /// <param name="forceStepToOwnMSD"></param> /// <returns>double potentialValue</returns> public double PFMaxShootingDistanceAttraction(double distanceToEnemy, Unit enemyUnit, double forceToOwnMSD, double forceStepToOwnMSD) { int ownUnitMSD = MyUnit.UnitType.WeaponGround.AttackRangeMax; // / TileSize;// int enemyUnitMSD = enemyUnit.UnitType.WeaponGround.AttackRangeMax; int MSDDifference = ownUnitMSD - enemyUnitMSD; double potenTialValueMSD = 0; //Weight potenTialValueMSD is used to alter the relative strength of the current tile, which the unit stands on or the possible tiles the unit can go to. if (distanceToEnemy > ownUnitMSD) //GET CLOSER TO ENEMY return forceToOwnMSD - forceStepToOwnMSD * (distanceToEnemy - ownUnitMSD); if (MSDDifference > 0) { if (distanceToEnemy <= ownUnitMSD && distanceToEnemy > enemyUnitMSD) return forceToOwnMSD + distanceToEnemy; } else if (distanceToEnemy <= ownUnitMSD) //TOO CLOSE TO ENEMY return forceToOwnMSD; return potenTialValueMSD; }
internal static void OnUnitHide(Unit unit) { // Util.Logger.Instance.Log("unit hide: " + unit.UnitTypeEnum.ToString()); if (unit.IsMine) { if (unit.UnitTypeEnum == UnitTypes.Terran_Goliath || unit.UnitTypeEnum == UnitTypes.Terran_SiegeTankSiegeMode || unit.UnitTypeEnum == UnitTypes.Terran_SiegeTankTankMode || unit.UnitTypeEnum == UnitTypes.Terran_SiegeTankSiegeTurret || unit.UnitTypeEnum == UnitTypes.Terran_TankTurretTankMode) RemoveDeadUnitFromList(unit); } }
internal static void OnUnitShow(Unit unit) { //Util.Logger.Instance.Log("unit show: " + unit.UnitTypeEnum.ToString()); }
/// <summary> /// Orders the unit to follow the specified unit. /// See also: IsFollowing, TargetUnit /// </summary> /// <param name="unitTarget"></param> /// <returns></returns> public bool DoFollowUnit(Unit unitTarget) { return this.BwapiObject.follow(unitTarget.BwapiObject); }
internal static void OnUnitMorph(Unit unit) { //Util.Logger.Instance.Log("unit morph: " + unit.UnitTypeEnum.ToString()); }
/// <summary> /// Returns true if the given unit type can be built at the given build tile position. /// If builder is not null, the unit will be discarded when determining whether or not any ground units are blocking the build location. /// </summary> /// <param name="builder">Builder worker.</param> /// <param name="buildTile">Top left tile of the building.</param> /// <param name="building">Type of a building unit to build.</param> /// <returns></returns> public static bool CanBuildHere(Unit builder, BuildTile buildTile, UnitTypes building) { return SWIG.BWAPI.bwapi.Broodwar.canBuildHere(builder.BwapiObject, buildTile.BwapiObject, new SWIG.BWAPI.UnitType((int)building)); }
public static void OnUnitDiscover(Unit unit) {}
/// <summary> /// Returns true if the given unit can research the given tech type and there is enough resources required to research. /// </summary> /// <param name="unitWhereToResearch"></param> /// <param name="techType"></param> /// <returns></returns> public static bool CanResearch(Unit unitWhereToResearch, TechType techType) { return SWIG.BWAPI.bwapi.Broodwar.canResearch(unitWhereToResearch.BwapiObject, techType.BwapiObject); }
/// <summary> /// Returns true if the given unit can research the given tech type and there is enough resources required to research. /// </summary> /// <param name="unitWhereToResearch"></param> /// <param name="techType"></param> /// <returns></returns> public static bool CanResearch(Unit unitWhereToResearch, TechTypes techType) { return SWIG.BWAPI.bwapi.Broodwar.canResearch(unitWhereToResearch.BwapiObject, new SWIG.BWAPI.TechType((int)techType)); }
/// <summary> /// Returns true if the specified unit is a worker else false. /// </summary> /// <param name="unit"></param> /// <returns></returns> private static Boolean IsWorker(Unit unit) { return unit.UnitTypeEnum == UnitTypes.Terran_SCV || unit.UnitTypeEnum == UnitTypes.Zerg_Drone || unit.UnitTypeEnum == UnitTypes.Protoss_Probe; }
public Terran_Medic_Agent(Unit myUnit, UnitAgentOptimizedProperties opProp) : base(myUnit, opProp) { UnitAgentTypeName = "Terran_Medic_Agent"; //SightRange = 9; }
public static void OnUnitCreate(Unit unit) { //Util.Logger.Instance.Log("unit create: " + unit.UnitTypeEnum); }
public Terran_Marine_Agent(Unit myUnit, UnitAgentOptimizedProperties opProp) : base(myUnit, opProp) { UnitAgentTypeName = "Terran_Marine_Agent"; //SightRange = 7; //http://wiki.teamliquid.net/starcraft/Marine }
/// <summary> /// Remove the destroyed unit from the list where the unit is placed. /// </summary> /// <param name="unit"></param> private static void RemoveDeadUnitFromList(Unit unit) { if (unit.IsMine) { if (IsWorker(unit)) { foreach (UnitAgent ua in _myWorkers) { _myWorkers.Remove(ua); return; } } else { foreach (List<UnitAgent> squad in _myArmy) { foreach (UnitAgent ua in squad.Where(ua => ua.MyUnit.ID == unit.ID)) { squad.Remove(ua); return; } } } } }
/// <summary> /// Returns true if the given unit can upgrade the given upgrade type and there is enough resources required to upgrade. /// </summary> /// <param name="unitWhereToUpgrade"></param> /// <param name="upgradeType"></param> /// <returns></returns> public static bool CanUpgrade(Unit unitWhereToUpgrade, UpgradeTypes upgradeType) { return SWIG.BWAPI.bwapi.Broodwar.canUpgrade(unitWhereToUpgrade.BwapiObject, new SWIG.BWAPI.UpgradeType((int) upgradeType)); }
/// <summary> /// Returns true if current builder unit can make this unit type and there is enough resources, supply, /// tech and required units in order to make the given unit type. /// </summary> /// <param name="builder"></param> /// <param name="unitType"></param> /// <returns></returns> public static bool CanMake(Unit builder, UnitTypes unitType) { return SWIG.BWAPI.bwapi.Broodwar.canMake(builder.BwapiObject, new SWIG.BWAPI.UnitType((int)unitType)); }