Ejemplo n.º 1
0
 protected virtual void PostSweep(ContextRing ring)
 {
     if (Normalize)
     {
         ring.Normalize();
     }
 }
Ejemplo n.º 2
0
        protected override void PreSweep(ContextRing ring)
        {
            base.PreSweep(ring);

            AverageAngle = null;
            if (LocalTeammates.Any())
            {
                int count           = 0;
                var averageMomentum = Vector2.Zero;

                foreach (var fleet in LocalTeammates)
                {
                    var distance = Vector2.Distance(fleet.Center, this.Robot.Position);

                    if (distance >= MinimumRange && distance <= MaximumRange)
                    {
                        averageMomentum += fleet.Momentum;
                        count++;
                    }
                }
                if (count > 0)
                {
                    averageMomentum /= count;
                    AverageAngle     = MathF.Atan2(averageMomentum.Y, averageMomentum.X);
                }
            }
        }
Ejemplo n.º 3
0
        protected override void PreSweep(ContextRing ring)
        {
            var teamMode = Robot.HookComputer.Hook.TeamMode;

            DangerousBullets = Robot.SensorBullets.VisibleBullets
                               .Where(b => b.Group.Owner != Robot.FleetID)
                               .Where(b => !teamMode || b.Group.Color != Robot.Color)
                               .ToList();

            Projections        = DangerousBullets.Select(b => b.ProjectNew(Robot.GameTime + LookAheadMS).Position).ToList();
            PhantomProjections = new List <Vector2>();
            var muchFleets = Robot.SensorFleets.Others
                             .Select(f => new { Fleet = f, Distance = Vector2.Distance(Robot.Position, f.Center) })
                             .Where(p => MathF.Abs(p.Fleet.Center.X - Robot.Position.X) <= ViewportCrop.X &&
                                    MathF.Abs(p.Fleet.Center.Y - Robot.Position.Y) <= ViewportCrop.Y)
                             .Where(p => !Robot.HookComputer.Hook.TeamMode || p.Fleet.Color != Robot.Color);

            foreach (var flet in muchFleets)
            {
                // Projections.Append(RoboMath.ProjectClosest( Robot.HookComputer,flet.Fleet.Center,Robot.Position,LookAheadMS,flet.Fleet.Ships.Count()));

                foreach (var ship in flet.Fleet.Ships)
                {
                    PhantomProjections.Append(RoboMath.ProjectClosest(Robot.HookComputer, ship.Position, Robot.Position, LookAheadMS, flet.Fleet.Ships.Count()));
                }
            }
            ConsideredPoints = new List <Vector2>();
        }
Ejemplo n.º 4
0
        protected override void PreSweep(ContextRing ring)
        {
            Active = false;
            var fleet = Robot.SensorFleets.MyFleet;

            if (fleet != null)
            {
                if (Robot.SensorFleets.Others.Any())
                {
                    var closestOpponent = Robot.SensorFleets.Others
                                          .Where(f => Vector2.Distance(f.Center, fleet.Center) < ActiveRange)
                                          .OrderBy(f => Vector2.DistanceSquared(f.Center, fleet.Center))
                                          .FirstOrDefault();
                    if (((closestOpponent?.Ships?.Count ?? 0) != 0) && ((fleet.Ships?.Count ?? 0) != 0))
                    {
                        if (closestOpponent.Ships.Count / fleet.Ships.Count < AdvanceThreshold)
                        {
                            TargetPoint = closestOpponent.Center;
                            Active      = true;
                        }
                    }
                }
            }

            base.PreSweep(ring);
        }
Ejemplo n.º 5
0
        public ContextRing ResolutionMultiply(int multiplier)
        {
            var ring = new ContextRing(this.Weights.Length * multiplier)
            {
                RingWeight = this.RingWeight,
                Name       = this.Name,
                StepSize   = this.StepSize / multiplier
            };

            for (var i = 0; i < Weights.Length; i++)
            {
                for (var j = 0; j < multiplier; j++)
                {
                    ring.Weights[i * multiplier + j] = this.Weights[i];
                }
            }
            for (var i = 0; i < WeightsBoost.Length; i++)
            {
                for (var j = 0; j < multiplier; j++)
                {
                    ring.WeightsBoost[i * multiplier + j] = this.WeightsBoost[i];
                }
            }

            return(ring);
        }
Ejemplo n.º 6
0
        protected override void PreSweep(ContextRing ring)
        {
            base.PreSweep(ring);

            TargetPoint = null;
            if (LocalTeammates.Any() && this.Robot.SensorFleets.MyFleet != null)
            {
                var     myFleet       = this.Robot.SensorFleets.MyFleet;
                float   count         = 0;
                int     n             = 0;
                Vector2 accumulator   = Vector2.Zero;
                var     BestTeammates = LocalTeammates.Select(f =>
                {
                    return(new
                    {
                        Fleet = f,
                        Distance = (this.Robot.Position - f.Center).Length(),
                        FrontDistance = Vector2.Dot(this.Robot.Position - f.Center, myFleet.Momentum / myFleet.Momentum.Length()),
                        BackDistance = -Vector2.Dot(this.Robot.Position - f.Center, myFleet.Momentum / myFleet.Momentum.Length()),
                        LeftDistance = Vector2.Dot(this.Robot.Position - f.Center, new Vector2(myFleet.Momentum.Y, -myFleet.Momentum.X) / myFleet.Momentum.Length()),
                        RightDistance = -Vector2.Dot(this.Robot.Position - f.Center, new Vector2(myFleet.Momentum.Y, -myFleet.Momentum.X) / myFleet.Momentum.Length()),
                    });
                }).Select(f =>
                {
                    return(new
                    {
                        Fleet = f.Fleet,
                        Distance = f.Distance,
                        FrontDistance = f.FrontDistance < 0 ? float.MaxValue : f.FrontDistance,
                        BackDistance = f.BackDistance < 0 ? float.MaxValue : f.BackDistance,
                        LeftDistance = f.LeftDistance < 0 ? float.MaxValue : f.LeftDistance,
                        RightDistance = f.RightDistance < 0 ? float.MaxValue : f.RightDistance,
                    });
                });

                var BestLeft = BestTeammates.OrderBy(p => p.LeftDistance).Select(f =>
                                                                                 f.Fleet);
                var BestRight = BestTeammates.OrderBy(p => p.RightDistance).Select(f =>
                                                                                   f.Fleet);
                var BestFront = BestTeammates.OrderBy(p => p.FrontDistance).Select(f =>
                                                                                   f.Fleet);
                var BestBack = BestTeammates.OrderBy(p => p.BackDistance).Select(f =>
                                                                                 f.Fleet);
                var tms = BestBack.Take(MaxFleets).Concat(BestLeft.Take(MaxFleets)).Concat(BestRight.Take(MaxFleets)).Concat(BestFront.Take(MaxFleets));
                foreach (var fleet in tms)
                {
                    var distance = Vector2.Distance(fleet.Center, this.Robot.Position);
                    if (distance <= MaximumRange && distance >= MinimumRange)
                    {
                        accumulator += (fleet.Center + (fleet.Momentum * (1.0f)) * LookAheadMS);
                        count       += 1.0f;
                        n           += 1;
                    }
                }
                if (accumulator != Vector2.Zero && count > 0)
                {
                    TargetPoint = accumulator / ((float)count) + (this.Robot.SensorFleets.MyFleet == null ? Vector2.Zero : this.Robot.SensorFleets.MyFleet.Momentum * LookAheadMS);
                }
            }
        }
Ejemplo n.º 7
0
        protected override void PreSweep(ContextRing ring)
        {
            FiringInterceptAngles = new Dictionary <Fleet, float>();

            var myFleet = this.Robot.SensorFleets.MyFleet;

            if (myFleet == null)
            {
                return;
            }

            FleetsOfConcern = null;
            foreach (var fleet in this.Robot.SensorFleets.Others)
            {
                if (!this.Robot.SensorTeam.IsSameTeam(fleet))
                {
                    if (Vector2.Distance(fleet.Center, myFleet.Center) < MaximumRange)
                    {
                        if (FleetsOfConcern == null)
                        {
                            FleetsOfConcern = new List <Fleet>();
                        }
                        FleetsOfConcern.Add(fleet);
                        var angle = CalculateIntercept(fleet, myFleet.Center, myFleet.Momentum);
                        FiringInterceptAngles.Add(fleet, angle);
                    }
                }
            }

            Sleep(750);
        }
Ejemplo n.º 8
0
 public ContextRing(ContextRing template)
 {
     this.Weights      = template.Weights.ToArray();
     this.WeightsBoost = template.WeightsBoost.ToArray();
     this.StepSize     = template.StepSize;
     this.RingWeight   = template.RingWeight;
     this.Name         = template.Name;
 }
Ejemplo n.º 9
0
        protected override void PreSweep(ContextRing ring)
        {
            if (Robot.LeaderHuntMode)
            {
                TargetPoint = Robot.Leaderboard.Entries.FirstOrDefault()?.Position ?? Vector2.Zero;
            }

            base.PreSweep(ring);
        }
Ejemplo n.º 10
0
        public ContextRing Behave(int steps)
        {
            if (this.Robot.GameTime > SleepUntil)
            {
                //Console.WriteLine("Processing");
                var ring = new ContextRing(steps);
                this.PreSweep(ring);

                if (Robot?.SensorFleets?.MyFleet?.Ships != null)
                {
                    for (var i = 0; i < steps; i++)
                    {
                        var momentum = Robot.SensorFleets.MyFleet.Momentum;
                        var position = RoboMath.ShipThrustProjection(Robot.HookComputer,
                                                                     Robot.Position,
                                                                     ref momentum,
                                                                     Robot.SensorFleets.MyFleet.Ships.Count,
                                                                     ring.Angle(i),
                                                                     LookAheadMS
                                                                     );
                        var momentumBoost = momentum / momentum.Length() * Robot.HookComputer.Hook.BoostThrust;
                        var positionBoost = RoboMath.ShipThrustProjection(Robot.HookComputer,
                                                                          position,
                                                                          ref momentumBoost,
                                                                          Robot.SensorFleets.MyFleet.Ships.Count,
                                                                          ring.Angle(i),
                                                                          Math.Min(Robot.HookComputer.Hook.BoostDuration, LookAheadMS)
                                                                          );

                        ring.Weights[i]      = ScoreAngle(ring.Angle(i), position, momentum);
                        ring.WeightsBoost[i] = ScoreAngle(ring.Angle(i), positionBoost, momentumBoost);
                    }
                }

                ring.RingWeight = BehaviorWeight;

                this.PostSweep(ring);

                ring.Name = this.GetType().Name;
                LastRing  = ring;

                if (Cycle > 0)
                {
                    Sleep(Cycle);
                }

                return(ring);
            }
            else
            {
                //Console.WriteLine("Waiting");
                return(new ContextRing(LastRing));
            }
        }
Ejemplo n.º 11
0
        protected override void PreSweep(ContextRing ring)
        {
            var teamMode = Robot.HookComputer.Hook.TeamMode;

            DangerousBullets = Robot.SensorBullets.VisibleBullets
                               .Where(b => b.Group.Owner != Robot.FleetID)
                               .Where(b => !teamMode || b.Group.Color != Robot.Color)
                               .ToList();

            Projections      = DangerousBullets.Select(b => b.ProjectNew(Robot.GameTime + LookAheadMS).Position).ToList();
            ConsideredPoints = new List <Vector2>();
        }
Ejemplo n.º 12
0
 protected override void PreSweep(ContextRing ring)
 {
     if (Robot.SensorFleets.MyFleet != null)
     {
         var momentum = Robot.SensorFleets.MyFleet.Momentum;
         TargetAngle = MathF.Atan2(momentum.Y, momentum.X);
         Scale       = momentum.Length();
     }
     else
     {
         Scale = 0;
     }
 }
Ejemplo n.º 13
0
        protected override void PreSweep(ContextRing ring)
        {
            LocalTeammates  = new List <Fleet>();
            RemoteTeamMates = new List <Vector2>();

            if (this.Robot.HookComputer.Hook.TeamMode || this.Robot.SensorAllies.HasAllies)
            {
                var leaderboardEntries = this.Robot.HookComputer.Hook.TeamMode
                    ? this.Robot.Leaderboard.Entries.Skip(2)
                    : this.Robot.Leaderboard.Entries;

                foreach (var entry in leaderboardEntries)
                {
                    var fleet = this.Robot.SensorFleets.ByID(entry.FleetID);

                    if (this.Robot.SensorTeam.IsSameTeam(entry.Color) &&
                        entry.FleetID != this.Robot.FleetID)
                    {
                        if (fleet != null)
                        {
                            LocalTeammates.Add(fleet);
                        }
                        else
                        {
                            RemoteTeamMates.Add(entry.Position);
                        }
                    }

                    if (fleet != null && this.Robot.SensorAllies.IsAlly(fleet))
                    {
                        LocalTeammates.Add(fleet);
                    }

                    if (fleet == null && this.Robot.SensorAllies.IsAlly(entry))
                    {
                        RemoteTeamMates.Add(entry.Position);
                    }
                }

                Active = true;
            }
            else
            {
                Active = false;
            }

            base.PreSweep(ring);
        }
Ejemplo n.º 14
0
        protected override void PreSweep(ContextRing ring)
        {
            Active = false;
            var fleet = Robot.SensorFleets.MyFleet;

            if (fleet != null)
            {
                if (Robot.SensorFleets.Others.Any())
                {
                    var closestOpponent = Robot.SensorFleets.Others
                                          .Where(f => Vector2.Distance(f.Center, fleet.Center) < ActiveRange)
                                          .OrderBy(f => Vector2.DistanceSquared(f.Center, fleet.Center))
                                          .FirstOrDefault();
                    if (((closestOpponent?.Ships?.Count ?? 0) != 0) && ((fleet.Ships?.Count ?? 0) != 0))
                    {
                        var ratio = (float)(closestOpponent.Ships.Count) / fleet.Ships.Count;
                        if (ratio > 0 && ratio < AdvanceThreshold)
                        {
                            TargetPoint = closestOpponent.Center + closestOpponent.Momentum * LookAheadMS;

                            bool isClosing =
                                Vector2.Distance(fleet.Center + fleet.Momentum * LookAheadMS, TargetPoint)
                                - Vector2.Distance(fleet.Center, TargetPoint) > 100;

                            if (ratio < BoostThreshold &&
                                fleet.Ships.Count >= BoostMinimum &&
                                (Robot.GameTime - Robot.LastShot > 500)
                                //&& isClosing
                                )
                            {
                                Console.WriteLine($"{Robot.GameTime - Robot.LastShot}");

                                Robot.Boost();
                                ActiveUntil = Robot.GameTime + 400;
                            }

                            Active = true;
                        }
                    }
                }
            }

            base.PreSweep(ring);
        }
Ejemplo n.º 15
0
        protected override void PreSweep(ContextRing ring)
        {
            base.PreSweep(ring);

            TargetPoint = null;
            if (RemoteTeamMates.Any())
            {
                int     count       = 0;
                Vector2 accumulator = Vector2.Zero;
                foreach (var remote in RemoteTeamMates)
                {
                    var distance = Vector2.Distance(remote, this.Robot.Position);
                    if (distance <= MaximumRange && distance >= MinimumRange)
                    {
                        accumulator += remote;
                        count++;
                    }
                }
                if (accumulator != Vector2.Zero && count > 0)
                {
                    TargetPoint = accumulator / count;
                }
            }
        }
Ejemplo n.º 16
0
 protected override void PostSweep(ContextRing ring)
 {
     //ring.Normalize();
 }
Ejemplo n.º 17
0
 protected override void PreSweep(ContextRing ring)
 {
 }
Ejemplo n.º 18
0
 protected virtual void PreSweep(ContextRing ring)
 {
 }