public List <Action> TakeAction(int frame) { if (!Enabled) { return(new List <Action>()); } ; UpdateState(); UpdateTarget(); if (DistractionSquadState == DistractionSquadState.Regrouping) { // go to group up point and wait return(MicroController.Retreat(DistractionSquad, RegroupPoint, null, frame)); } else if (DistractionSquadState == DistractionSquadState.Enroute) { // TODO: follow the path to the distraction target return(MicroController.Attack(DistractionSquad, DistractionTarget, RegroupPoint, null, frame)); } else if (DistractionSquadState == DistractionSquadState.Distracting) { // attack stuff and distract, bait away from main army's target return(MicroController.Attack(DistractionSquad, DistractionTarget, RegroupPoint, null, frame)); } return(new List <Action>()); }
public List <SC2APIProtocol.Action> CleanupEnemies(IEnumerable <UnitCommander> commanders, Point2D defensivePoint, Point2D armyPoint, int frame) { if (commanders.Count() == 0) { return(null); } var winners = commanders.Where(u => u.UnitCalculation.TargetPriorityCalculation.Overwhelm && u.UnitCalculation.NearbyEnemies.Count() > 0 && !u.UnitCalculation.NearbyAllies.Any(a => a.TargetPriorityCalculation.TargetPriority == TargetPriority.Retreat || a.TargetPriorityCalculation.TargetPriority == TargetPriority.FullRetreat)); if (winners.Count() == 0) { winners = commanders.Where(u => u.UnitCalculation.TargetPriorityCalculation.OverallWinnability > 1 && u.UnitCalculation.NearbyEnemies.Count() > 0 && !u.UnitCalculation.NearbyAllies.Any(a => a.TargetPriorityCalculation.TargetPriority == TargetPriority.Retreat || a.TargetPriorityCalculation.TargetPriority == TargetPriority.FullRetreat)); } if (winners.Count() > 0) { var defenseVector = new Vector2(defensivePoint.X, defensivePoint.Y); var winner = winners.OrderBy(u => Vector2.DistanceSquared(u.UnitCalculation.Position, defenseVector)).FirstOrDefault(); var winPoint = winner.UnitCalculation.NearbyEnemies.FirstOrDefault().Position; return(MicroController.Attack(commanders, new Point2D { X = winPoint.X, Y = winPoint.Y }, defensivePoint, armyPoint, frame)); } return(null); }
public override IEnumerable <SC2APIProtocol.Action> PerformActions(int frame) { var actions = new List <SC2APIProtocol.Action>(); if (lastFrameTime > 5) { lastFrameTime = 0; return(actions); } var stopwatch = new Stopwatch(); stopwatch.Start(); var attackingEnemies = ActiveUnitData.SelfUnits.Where(u => u.Value.Attributes.Contains(Attribute.Structure)).SelectMany(u => u.Value.NearbyEnemies).Distinct().Where(e => ActiveUnitData.EnemyUnits.ContainsKey(e.Unit.Tag)); if (attackingEnemies.Count() > 0) { if (UnitCommanders.Count() == 0) { actions.AddRange(DefendWithWorkers(attackingEnemies, frame)); } else { StopDefendingWithWorkers(); } foreach (var commander in UnitCommanders) { if (commander.UnitCalculation.TargetPriorityCalculation.TargetPriority == TargetPriority.Retreat || commander.UnitCalculation.TargetPriorityCalculation.TargetPriority == TargetPriority.FullRetreat) { commander.UnitCalculation.TargetPriorityCalculation.TargetPriority = TargetPriority.Attack; } } actions.AddRange(ArmySplitter.SplitArmy(frame, attackingEnemies, TargetingData.MainDefensePoint, UnitCommanders, true)); stopwatch.Stop(); lastFrameTime = stopwatch.ElapsedMilliseconds; return(actions); } else { actions = MicroController.Attack(UnitCommanders, TargetingData.MainDefensePoint, TargetingData.ForwardDefensePoint, TargetingData.MainDefensePoint, frame); } StopDefendingWithWorkers(); stopwatch.Stop(); lastFrameTime = stopwatch.ElapsedMilliseconds; return(actions); }
public override IEnumerable <SC2APIProtocol.Action> PerformActions(int frame) { var actions = new List <SC2APIProtocol.Action>(); if (lastFrameTime > 5) { lastFrameTime = 0; return(actions); } var stopwatch = new Stopwatch(); stopwatch.Start(); var mainUnits = UnitCommanders.Where(c => MainAttackers.Contains((UnitTypes)c.UnitCalculation.Unit.UnitType)); var otherUnits = UnitCommanders.Where(c => !MainAttackers.Contains((UnitTypes)c.UnitCalculation.Unit.UnitType)); DistractionSquadService.UpdateDistractionSquad(otherUnits); DistractionSquadService.Enabled = UnitCommanders.Count() > 25; IEnumerable <UnitCommander> supportUnits; if (DistractionSquadService.DistractionSquadState == DistractionSquadState.NotDistracting) { supportUnits = otherUnits; } else { supportUnits = otherUnits.Where(c => !DistractionSquadService.DistractionSquad.Any(d => d.UnitCalculation.Unit.Tag == c.UnitCalculation.Unit.Tag)); } var hiddenBase = TargetingData.HiddenEnemyBase; if (mainUnits.Count() > 0) { AttackData.ArmyPoint = TargetingService.GetArmyPoint(mainUnits); } else { AttackData.ArmyPoint = TargetingService.GetArmyPoint(supportUnits); } TargetingData.AttackPoint = TargetingService.UpdateAttackPoint(AttackData.ArmyPoint, TargetingData.AttackPoint); var attackingEnemies = ActiveUnitData.SelfUnits.Where(u => u.Value.UnitClassifications.Contains(UnitClassification.ResourceCenter) || u.Value.UnitClassifications.Contains(UnitClassification.ProductionStructure) || u.Value.UnitClassifications.Contains(UnitClassification.DefensiveStructure)).SelectMany(u => u.Value.NearbyEnemies).Distinct(); if (attackingEnemies.Count() > 0) { var armyPoint = new Vector2(AttackData.ArmyPoint.X, AttackData.ArmyPoint.Y); var distanceToAttackPoint = Vector2.DistanceSquared(armyPoint, new Vector2(TargetingData.AttackPoint.X, TargetingData.AttackPoint.Y)); var closerEnemies = attackingEnemies; if (AttackData.Attacking) { closerEnemies = attackingEnemies.Where(e => Vector2.DistanceSquared(e.Position, armyPoint) < distanceToAttackPoint); } if (closerEnemies.Count() > 0) { actions = ArmySplitter.SplitArmy(frame, closerEnemies, TargetingData.AttackPoint, mainUnits.Concat(supportUnits), false); stopwatch.Stop(); lastFrameTime = stopwatch.ElapsedMilliseconds; return(actions); } } if (!hiddenBase && TargetingData.HiddenEnemyBase) { ResetClaimedUnits(); if (MicroTaskData.MicroTasks.ContainsKey("FindHiddenBaseTask")) { MicroTaskData.MicroTasks["FindHiddenBaseTask"].Enable(); } } else if (hiddenBase && !TargetingData.HiddenEnemyBase) { if (MicroTaskData.MicroTasks.ContainsKey("FindHiddenBaseTask")) { MicroTaskData.MicroTasks["FindHiddenBaseTask"].Disable(); } } actions.AddRange(DistractionSquadService.TakeAction(frame)); if (mainUnits.Count() > 0) { if (AttackData.Attacking) { actions.AddRange(MicroController.Attack(mainUnits, TargetingData.AttackPoint, TargetingData.ForwardDefensePoint, AttackData.ArmyPoint, frame)); actions.AddRange(MicroController.Support(supportUnits, mainUnits, TargetingData.AttackPoint, TargetingData.ForwardDefensePoint, AttackData.ArmyPoint, frame)); } else { var cleanupActions = EnemyCleanupService.CleanupEnemies(mainUnits.Concat(supportUnits), TargetingData.ForwardDefensePoint, AttackData.ArmyPoint, frame); if (cleanupActions != null) { actions.AddRange(cleanupActions); } else { actions.AddRange(MicroController.Retreat(mainUnits, TargetingData.ForwardDefensePoint, null, frame)); actions.AddRange(MicroController.Retreat(supportUnits, TargetingData.ForwardDefensePoint, null, frame)); } } } else { if (AttackData.Attacking) { actions.AddRange(MicroController.Attack(supportUnits, TargetingData.AttackPoint, TargetingData.ForwardDefensePoint, AttackData.ArmyPoint, frame)); } else { var cleanupActions = EnemyCleanupService.CleanupEnemies(supportUnits, TargetingData.ForwardDefensePoint, AttackData.ArmyPoint, frame); if (cleanupActions != null) { actions.AddRange(cleanupActions); } else { actions.AddRange(MicroController.Retreat(supportUnits, TargetingData.ForwardDefensePoint, AttackData.ArmyPoint, frame)); } } } stopwatch.Stop(); lastFrameTime = stopwatch.ElapsedMilliseconds; return(actions); }
public override IEnumerable <SC2APIProtocol.Action> PerformActions(int frame) { var actions = new List <SC2APIProtocol.Action>(); if (lastFrameTime > 5) { lastFrameTime = 0; return(actions); } var stopwatch = new Stopwatch(); stopwatch.Start(); var hiddenBase = TargetingData.HiddenEnemyBase; AttackData.ArmyPoint = TargetingService.GetArmyPoint(UnitCommanders); TargetingData.AttackPoint = TargetingService.UpdateAttackPoint(AttackData.ArmyPoint, TargetingData.AttackPoint); if (!AttackData.CustomAttackFunction) { if (AttackData.Attacking) { if (MacroData.FoodUsed < AttackData.ArmyFoodRetreat) { AttackData.Attacking = false; } } else { AttackData.Attacking = MacroData.FoodArmy >= AttackData.ArmyFoodAttack || MacroData.FoodUsed > 190; } } var attackingEnemies = ActiveUnitData.SelfUnits.Where(u => u.Value.UnitClassifications.Contains(UnitClassification.ResourceCenter) || u.Value.UnitClassifications.Contains(UnitClassification.ProductionStructure)).SelectMany(u => u.Value.NearbyEnemies).Distinct(); if (attackingEnemies.Count() > 0) { var armyPoint = new Vector2(AttackData.ArmyPoint.X, AttackData.ArmyPoint.Y); var distanceToAttackPoint = Vector2.DistanceSquared(armyPoint, new Vector2(TargetingData.AttackPoint.X, TargetingData.AttackPoint.Y)); var closerEnemies = attackingEnemies.Where(e => Vector2.DistanceSquared(e.Position, armyPoint) < distanceToAttackPoint); if (!AttackData.Attacking) { closerEnemies = attackingEnemies; } if (closerEnemies.Count() > 0) { actions = ArmySplitter.SplitArmy(frame, closerEnemies, TargetingData.AttackPoint, UnitCommanders, false); stopwatch.Stop(); lastFrameTime = stopwatch.ElapsedMilliseconds; return(actions); } } if (!hiddenBase && TargetingData.HiddenEnemyBase) { ResetClaimedUnits(); if (MicroTaskData.MicroTasks.ContainsKey("FindHiddenBaseTask")) { MicroTaskData.MicroTasks["FindHiddenBaseTask"].Enable(); } } else if (!TargetingData.HiddenEnemyBase) { if (MicroTaskData.MicroTasks.ContainsKey("FindHiddenBaseTask") && MicroTaskData.MicroTasks["FindHiddenBaseTask"].Enabled) { MicroTaskData.MicroTasks["FindHiddenBaseTask"].Disable(); } } if (AttackData.Attacking) { actions = MicroController.Attack(UnitCommanders, TargetingData.AttackPoint, TargetingData.ForwardDefensePoint, AttackData.ArmyPoint, frame); stopwatch.Stop(); lastFrameTime = stopwatch.ElapsedMilliseconds; return(actions); } else { var cleanupActions = EnemyCleanupService.CleanupEnemies(UnitCommanders, TargetingData.ForwardDefensePoint, AttackData.ArmyPoint, frame); if (cleanupActions != null) { actions = cleanupActions; } else { actions = MicroController.Retreat(UnitCommanders, TargetingData.ForwardDefensePoint, AttackData.ArmyPoint, frame); } stopwatch.Stop(); lastFrameTime = stopwatch.ElapsedMilliseconds; return(actions); } }
public override IEnumerable <SC2APIProtocol.Action> PerformActions(int frame) { SetLocations(); var actions = new List <SC2APIProtocol.Action>(); if (lastFrameTime > 5) { lastFrameTime = 0; return(actions); } var stopwatch = new Stopwatch(); stopwatch.Start(); CheckComplete(); var warpPrisms = UnitCommanders.Where(c => c.UnitCalculation.Unit.UnitType == (uint)UnitTypes.PROTOSS_WARPPRISM || c.UnitCalculation.Unit.UnitType == (uint)UnitTypes.PROTOSS_WARPPRISMPHASING); var attackers = UnitCommanders.Where(c => c.UnitCalculation.Unit.UnitType != (uint)UnitTypes.PROTOSS_WARPPRISM && c.UnitCalculation.Unit.UnitType != (uint)UnitTypes.PROTOSS_WARPPRISMPHASING); var droppedAttackers = attackers.Where(c => AreaService.InArea(c.UnitCalculation.Unit.Pos, DropArea)); var unDroppedAttackers = attackers.Where(c => !AreaService.InArea(c.UnitCalculation.Unit.Pos, DropArea)); if (warpPrisms.Count() > 0) { foreach (var commander in warpPrisms) { var action = OrderWarpPrism(commander, droppedAttackers, unDroppedAttackers, frame); if (action != null) { actions.AddRange(action); } } // move into the loading position foreach (var commander in unDroppedAttackers) { var action = commander.Order(frame, Abilities.ATTACK, LoadingLocation); if (action != null) { actions.AddRange(action); } } //actions.AddRange(MicroController.Retreat(unDroppedAttackers, LoadingLocation, null, frame)); } else { if (droppedAttackers.Count() > 0) { // don't wait for another warp prism, just attack actions.AddRange(MicroController.Attack(unDroppedAttackers, TargetLocation, DefensiveLocation, null, frame)); } else { // wait for a warp prism actions.AddRange(MicroController.Retreat(unDroppedAttackers, DefensiveLocation, null, frame)); } } actions.AddRange(MicroController.Attack(droppedAttackers, TargetLocation, DefensiveLocation, null, frame)); stopwatch.Stop(); lastFrameTime = stopwatch.ElapsedMilliseconds; return(actions); }
public List <SC2APIProtocol.Action> SplitArmy(int frame, IEnumerable <UnitCalculation> closerEnemies, Point2D attackPoint, IEnumerable <UnitCommander> unitCommanders, bool defendToDeath) { var actions = new List <SC2APIProtocol.Action>(); var winnableDefense = false; if (LastSplitFrame + 25 < frame) { ReSplitArmy(frame, closerEnemies, attackPoint, unitCommanders); LastSplitFrame = frame; } foreach (var split in ArmySplits) { if (split.SelfGroup.Count() > 0) { var groupVectors = split.SelfGroup.Select(u => u.UnitCalculation.Position); var groupPoint = new Point2D { X = groupVectors.Average(v => v.X), Y = groupVectors.Average(v => v.Y) }; var defensePoint = new Point2D { X = split.EnemyGroup.FirstOrDefault().Unit.Pos.X, Y = split.EnemyGroup.FirstOrDefault().Unit.Pos.Y }; actions.AddRange(MicroController.Attack(split.SelfGroup, defensePoint, TargetingData.ForwardDefensePoint, groupPoint, frame)); winnableDefense = true; } } if (AvailableCommanders.Count() > 0) { var groupVectors = AvailableCommanders.Select(u => u.UnitCalculation.Position); var groupPoint = new Point2D { X = groupVectors.Average(v => v.X), Y = groupVectors.Average(v => v.Y) }; if (AttackData.Attacking) { actions.AddRange(MicroController.Attack(AvailableCommanders, attackPoint, TargetingData.ForwardDefensePoint, groupPoint, frame)); } else { if (winnableDefense || defendToDeath) { actions.AddRange(MicroController.Attack(AvailableCommanders, new Point2D { X = closerEnemies.FirstOrDefault().Unit.Pos.X, Y = closerEnemies.FirstOrDefault().Unit.Pos.Y }, TargetingData.ForwardDefensePoint, groupPoint, frame)); } else { var defensiveVector = new Vector2(TargetingData.ForwardDefensePoint.X, TargetingData.ForwardDefensePoint.Y); var shieldBattery = ActiveUnitData.SelfUnits.Values.Where(u => u.Unit.UnitType == (uint)UnitTypes.PROTOSS_SHIELDBATTERY && u.Unit.IsPowered && u.Unit.BuildProgress == 1 && u.Unit.Energy > 5).OrderBy(u => Vector2.DistanceSquared(u.Position, defensiveVector)).FirstOrDefault(); if (shieldBattery != null) { actions.AddRange(MicroController.Retreat(AvailableCommanders, new Point2D { X = shieldBattery.Position.X, Y = shieldBattery.Position.Y }, groupPoint, frame)); } else { actions.AddRange(MicroController.Retreat(AvailableCommanders, TargetingData.MainDefensePoint, groupPoint, frame)); } } } } return(actions); }