Example #1
0
        void RemoveLostWorkers()
        {
            foreach (var commander in UnitCommanders.Where(c => c.UnitRole == UnitRole.Minerals))
            {
                if (!BaseData.SelfBases.Any(selfBase => selfBase.MineralMiningInfo.Any(i => i.Workers.Any(w => w.UnitCalculation.Unit.Tag == commander.UnitCalculation.Unit.Tag))))
                {
                    commander.UnitRole = UnitRole.None;
                }
            }
            foreach (var commander in UnitCommanders.Where(c => c.UnitRole == UnitRole.Gas))
            {
                if (!BaseData.SelfBases.Any(selfBase => selfBase.GasMiningInfo.Any(i => i.Workers.Any(w => w.UnitCalculation.Unit.Tag == commander.UnitCalculation.Unit.Tag))))
                {
                    commander.UnitRole = UnitRole.None;
                }
            }

            foreach (var selfBase in BaseData.SelfBases)
            {
                foreach (var info in selfBase.MineralMiningInfo)
                {
                    info.Workers.RemoveAll(w => w.UnitRole != UnitRole.Minerals || !UnitCommanders.Any(c => c.UnitCalculation.Unit.Tag == w.UnitCalculation.Unit.Tag));
                }
                foreach (var info in selfBase.GasMiningInfo)
                {
                    info.Workers.RemoveAll(w => w.UnitRole != UnitRole.Gas || !UnitCommanders.Any(c => c.UnitCalculation.Unit.Tag == w.UnitCalculation.Unit.Tag));
                }
            }
        }
        public override IEnumerable <SC2APIProtocol.Action> PerformActions(int frame)
        {
            if (ScoutLocations == null)
            {
                GetScoutLocations();
            }

            var commands = new List <SC2APIProtocol.Action>();

            if (!UnitCommanders.Any(c => c.UnitCalculation.Unit.IsHallucination && c.UnitCalculation.Unit.UnitType == (uint)UnitTypes.PROTOSS_PHOENIX))
            {
                foreach (var commander in UnitCommanders)
                {
                    if (commander.UnitCalculation.Unit.UnitType == (uint)UnitTypes.PROTOSS_SENTRY && commander.UnitCalculation.Unit.Energy >= 75)
                    {
                        var action = commander.Order(frame, Abilities.HALLUCINATION_PHOENIX);
                        if (action != null)
                        {
                            commands.AddRange(action);
                        }
                    }
                }
            }
            else
            {
                foreach (var commander in UnitCommanders)
                {
                    if (commander.UnitCalculation.Unit.UnitType == (uint)UnitTypes.PROTOSS_PHOENIX)
                    {
                        if (Vector2.DistanceSquared(new Vector2(ScoutLocations[ScoutLocationIndex].X, ScoutLocations[ScoutLocationIndex].Y), commander.UnitCalculation.Position) < 2)
                        {
                            ScoutLocationIndex++;
                            if (ScoutLocationIndex >= ScoutLocations.Count())
                            {
                                ScoutLocationIndex = 0;
                            }
                        }
                        else
                        {
                            var action = commander.Order(frame, Abilities.MOVE, ScoutLocations[ScoutLocationIndex]);
                            if (action != null)
                            {
                                commands.AddRange(action);
                            }
                        }
                    }
                }
            }

            return(commands);
        }
        void AssignHarassers()
        {
            if (HarassInfos == null)
            {
                HarassInfos = new List <HarassInfo>();
                foreach (var baseLocation in BaseData.BaseLocations.Where(b => b.ResourceCenter == null || b.ResourceCenter.Alliance != SC2APIProtocol.Alliance.Self).Reverse())
                {
                    HarassInfos.Add(new HarassInfo {
                        BaseLocation = baseLocation, Harassers = new List <UnitCommander>(), LastClearedFrame = -1, LastDefendedFrame = -1, LastPathFailedFrame = -1
                    });
                }
            }
            else
            {
                foreach (var baseLocation in BaseData.SelfBases)
                {
                    HarassInfos.RemoveAll(h => h.BaseLocation.Location.X == baseLocation.Location.X && h.BaseLocation.Location.Y == baseLocation.Location.Y);
                }
                foreach (var harassInfo in HarassInfos)
                {
                    harassInfo.Harassers.RemoveAll(h => !UnitCommanders.Any(u => u.UnitCalculation.Unit.Tag == h.UnitCalculation.Unit.Tag));
                }
            }

            if (HarassInfos.Count() > 0)
            {
                var unasignedCommanders = UnitCommanders.Where(u => !HarassInfos.Any(info => info.Harassers.Any(h => h.UnitCalculation.Unit.Tag == u.UnitCalculation.Unit.Tag))).ToList();
                while (unasignedCommanders.Count() > 0)
                {
                    foreach (var info in HarassInfos.OrderBy(h => h.Harassers.Count()).ThenBy(h => HighestFrame(h)))
                    {
                        var commander = unasignedCommanders.First();
                        info.Harassers.Add(commander);
                        unasignedCommanders.Remove(commander);
                        if (unasignedCommanders.Count() == 0)
                        {
                            return;
                        }
                    }
                }
            }
        }
        public override void ClaimUnits(ConcurrentDictionary <ulong, UnitCommander> commanders)
        {
            if (UnitCommanders.Count() < 2)
            {
                if (started)
                {
                    Disable();
                    return;
                }

                if (!UnitCommanders.Any(c => c.UnitCalculation.Unit.UnitType == (uint)UnitTypes.PROTOSS_SENTRY))
                {
                    foreach (var commander in commanders)
                    {
                        if (!commander.Value.Claimed && commander.Value.UnitCalculation.Unit.UnitType == (uint)UnitTypes.PROTOSS_SENTRY)
                        {
                            commander.Value.Claimed = true;
                            UnitCommanders.Add(commander.Value);
                            break;
                        }
                    }
                }
                if (!UnitCommanders.Any(c => c.UnitCalculation.Unit.IsHallucination && c.UnitCalculation.Unit.UnitType == (uint)UnitTypes.PROTOSS_PHOENIX))
                {
                    foreach (var commander in commanders)
                    {
                        if (!commander.Value.Claimed && commander.Value.UnitCalculation.Unit.IsHallucination && commander.Value.UnitCalculation.Unit.UnitType == (uint)UnitTypes.PROTOSS_PHOENIX)
                        {
                            commander.Value.Claimed  = true;
                            commander.Value.UnitRole = UnitRole.Scout;
                            UnitCommanders.Add(commander.Value);
                            break;
                        }
                    }
                }
            }
            else
            {
                started = true;
            }
        }
Example #5
0
        void AssignHarassers()
        {
            if (HarassInfos == null)
            {
                HarassInfos = new List <HarassInfo>();
                foreach (var baseLocation in BaseData.BaseLocations.Where(b => b.ResourceCenter == null || b.ResourceCenter.Alliance != SC2APIProtocol.Alliance.Self).Reverse())
                {
                    HarassInfos.Add(new HarassInfo {
                        BaseLocation = baseLocation, Harassers = new List <UnitCommander>(), LastClearedFrame = -1, LastDefendedFrame = -1, LastPathFailedFrame = -1
                    });
                }
            }
            else
            {
                foreach (var baseLocation in BaseData.SelfBases)
                {
                    HarassInfos.RemoveAll(h => h.BaseLocation.Location.X == baseLocation.Location.X && h.BaseLocation.Location.Y == baseLocation.Location.Y);
                }
                foreach (var harassInfo in HarassInfos)
                {
                    harassInfo.Harassers.RemoveAll(h => !UnitCommanders.Any(u => u.UnitCalculation.Unit.Tag == h.UnitCalculation.Unit.Tag));
                }
            }

            if (ScoutInfos == null)
            {
                ScoutInfos = new List <ScoutInfo>();
                ScoutInfos.Add(new ScoutInfo {
                    Harassers = new List <UnitCommander>(), LastClearedFrame = -1, LastDefendedFrame = -1, LastPathFailedFrame = -1, Location = new SC2APIProtocol.Point2D {
                        X = 5, Y = 5
                    }
                });
                ScoutInfos.Add(new ScoutInfo {
                    Harassers = new List <UnitCommander>(), LastClearedFrame = -1, LastDefendedFrame = -1, LastPathFailedFrame = -1, Location = new SC2APIProtocol.Point2D {
                        X = MapDataService.MapData.MapWidth - 5, Y = 5
                    }
                });
                ScoutInfos.Add(new ScoutInfo {
                    Harassers = new List <UnitCommander>(), LastClearedFrame = -1, LastDefendedFrame = -1, LastPathFailedFrame = -1, Location = new SC2APIProtocol.Point2D {
                        X = 5, Y = MapDataService.MapData.MapHeight - 5
                    }
                });
                ScoutInfos.Add(new ScoutInfo {
                    Harassers = new List <UnitCommander>(), LastClearedFrame = -1, LastDefendedFrame = -1, LastPathFailedFrame = -1, Location = new SC2APIProtocol.Point2D {
                        X = MapDataService.MapData.MapWidth - 5, Y = MapDataService.MapData.MapHeight - 5
                    }
                });
            }
            else
            {
                foreach (var scoutInfo in ScoutInfos)
                {
                    scoutInfo.Harassers.RemoveAll(h => !UnitCommanders.Any(u => u.UnitCalculation.Unit.Tag == h.UnitCalculation.Unit.Tag));
                }
            }

            var unasignedCommanders = UnitCommanders.Where(u => !HarassInfos.Any(info => info.Harassers.Any(h => h.UnitCalculation.Unit.Tag == u.UnitCalculation.Unit.Tag) || ScoutInfos.Any(info => info.Harassers.Any(h => h.UnitCalculation.Unit.Tag == u.UnitCalculation.Unit.Tag)))).ToList();

            foreach (var scoutInfo in ScoutInfos)
            {
                if (unasignedCommanders.Count() > 0)
                {
                    foreach (var info in ScoutInfos.Where(h => h.Harassers.Count() == 0))
                    {
                        var commander = unasignedCommanders.FirstOrDefault(c => c.UnitCalculation.Unit.IsFlying);
                        if (commander != null)
                        {
                            info.Harassers.Add(commander);
                            unasignedCommanders.Remove(commander);
                            if (unasignedCommanders.Count() == 0)
                            {
                                return;
                            }
                        }
                    }
                }
            }

            if (HarassInfos.Count() > 0)
            {
                while (unasignedCommanders.Count() > 0)
                {
                    foreach (var info in HarassInfos.OrderBy(h => h.Harassers.Count()).ThenBy(h => HighestFrame(h)))
                    {
                        var commander = unasignedCommanders.First();
                        info.Harassers.Add(commander);
                        unasignedCommanders.Remove(commander);
                        if (unasignedCommanders.Count() == 0)
                        {
                            return;
                        }
                    }
                }
            }
        }
Example #6
0
 public override void ClaimUnits(ConcurrentDictionary <ulong, UnitCommander> commanders)
 {
     foreach (var commander in commanders)
     {
         if (commander.Value.UnitCalculation.UnitClassifications.Contains(UnitClassification.Worker) && !UnitCommanders.Any(c => c.UnitCalculation.Unit.Tag == commander.Key))
         {
             commander.Value.Claimed = true;
             UnitCommanders.Add(commander.Value);
         }
     }
 }