Ejemplo n.º 1
0
        protected override Task AliveAsync()
        {
            // await base.AliveAsync();

            foreach (var sensor in Sensors)
            {
                sensor.Sense();
            }
            var contexts = ContextBehaviors.Select(b => b.Behave(Steps)).ToList();

            (var finalRing, var angle, var boost) = ContextRingBlending.Blend(contexts, true);
            SteerAngle(angle);
            var willShoot = CanShoot;

            if (CanBoost && boost && (this.SensorFleets.MyFleet?.Ships.Count ?? 0) > BoostThreshold)
            {
                if (ShootUntil < GameTime)
                {
                    Boost();
                }
                willShoot = false;
            }
            if (CanShoot && willShoot)
            {
                var target = (AttackFleets ? FleetTargeting.ChooseTarget() : null)
                             ?? (AttackAbandoned ? AbandonedTargeting.ChooseTarget() : null)
                             ?? (AttackFish ? FishTargeting.ChooseTarget() : null);

                if (target != null)
                {
                    var  shootAngle = MathF.Atan2(target.Position.Y - this.Position.Y, target.Position.X - this.Position.X);
                    bool dangerous  = false;
                    if (!AttackFleets && this.SensorFleets.MyFleet != null)
                    {
                        var flets = FleetTargeting.PotentialTargetFleets();
                        foreach (var flet in flets)
                        {
                            if (RoboMath.MightHit(this.HookComputer, this.SensorFleets.MyFleet, flet, shootAngle))
                            {
                                dangerous = true;
                            }
                        }
                    }
                    if (!Safe || !dangerous)
                    {
                        ShootAt(target.Position);
                    }
                }
            }



            if (ReloadConfigAfter > 0 && ReloadConfigAfter < GameTime)
            {
                LoadConfig();
                ReloadConfigAfter = 0;
            }

            return(Task.FromResult(0));
        }
Ejemplo n.º 2
0
        protected async override Task AliveAsync()
        {
            await base.AliveAsync();

            // when shooting becomes available
            // lets see if we should delay
            if (!LastCanShoot && CanShoot)
            {
                DeferShootUntil = GameTime + FiringDelayMS;
            }
            LastCanShoot = CanShoot;

            if (CanShoot && DeferShootUntil < GameTime)
            {
                var target = (AttackFleets ? FleetTargeting.ChooseTarget() : null)
                             ?? (AttackAbandoned ? AbandonedTargeting.ChooseTarget() : null)
                             ?? (AttackFish ? FishTargeting.ChooseTarget() : null);

                if (target != null)
                {
                    ShootAt(target.Position);
                }
            }

            if (CanBoost && (this.SensorFleets.MyFleet?.Ships.Count ?? 0) > BoostThreshold)
            {
                Boost();
            }
        }
Ejemplo n.º 3
0
        protected async override Task AliveAsync()
        {
            await base.AliveAsync();

            // when shooting becomes available
            // lets see if we should delay
            if (!LastCanShoot && CanShoot)
            {
                DeferShootUntil = GameTime + FiringDelayMS;
            }
            LastCanShoot = CanShoot;

            if (CanShoot && DeferShootUntil < GameTime)
            {
                var target = (AttackFleets ? FleetTargeting.ChooseTarget() : null)
                             ?? (AttackAbandoned ? AbandonedTargeting.ChooseTarget() : null)
                             ?? (AttackFish ? FishTargeting.ChooseTarget() : null);

                if (target != null)
                {
                    var  shootAngle = MathF.Atan2(target.Position.Y - this.Position.Y, target.Position.X - this.Position.X);
                    bool dangerous  = false;
                    if (!AttackFleets && this.SensorFleets.MyFleet != null)
                    {
                        var flets = FleetTargeting.PotentialTargetFleets();
                        foreach (var flet in flets)
                        {
                            if (RoboMath.MightHit(this.HookComputer, this.SensorFleets.MyFleet, flet, shootAngle))
                            {
                                dangerous = true;
                            }
                        }
                    }
                    if (!Safe || !dangerous)
                    {
                        ShootAt(target.Position);
                    }
                }
            }

            if (CanBoost && (this.SensorFleets.MyFleet?.Ships.Count ?? 0) > BoostThreshold)
            {
                Boost();
            }
        }
Ejemplo n.º 4
0
        protected override Task AliveAsync()
        {
            foreach (var sensor in Sensors)
            {
                sensor.Sense();
            }

            if (SensorCTF.CTFModeEnabled)
            {
                if (SensorCTF.IsCarryingFlag)
                {
                    // I'm carrying the flag

                    if (SensorCTF.OurTeam.FlagIsHome)
                    {
                        // our flag is home, head to base to score
                        Navigation.TargetPoint = SensorCTF.OurTeam.BasePosition;
                    }
                    else
                    {
                        // our flag is not home, attack the guy who stole it
                        // this seems required for 1v1, we might get trickier and
                        // change behavior here if we have a teammate
                        Navigation.TargetPoint = SensorCTF.OurTeam.FlagPosition;
                    }
                }
                else
                {
                    // I'm not carrying a flag

                    if (!SensorCTF.TheirTeam.FlagIsHome)
                    {
                        // our teammate is carrying a flag
                        if (!SensorCTF.OurTeam.FlagIsHome)
                        {
                            // our flag is not home, attack it
                            Navigation.TargetPoint = SensorCTF.OurTeam.FlagPosition;
                        }
                        else
                        {
                            // our flag is home, defend teammate
                            Navigation.TargetPoint = SensorCTF.TheirTeam.FlagPosition;
                        }
                    }
                    else
                    {
                        // their flag is home
                        Navigation.TargetPoint = SensorCTF.TheirTeam.BasePosition;
                    }
                }
            }

            var contexts = ContextBehaviors.Select(b => b.Behave(Steps)).ToList();
            var bangle   = 0.0f;

            if (SensorFleets.MyFleet != null)
            {
                bangle = MathF.Atan2(this.SensorFleets.MyFleet.Momentum.Y, this.SensorFleets.MyFleet.Momentum.X);
            }
            (var finalRing, var angle, var boost) = ContextRingBlending.Blend(contexts, false);
            var combined = new ContextRing(this.Steps);


            // blur

            // lock (typeof(ContextRingBlendingWeighted))
            // {
            //     Console.SetCursorPosition(0, 0);
            //     Console.WriteLine("RingDump");
            //     foreach (var context in contexts)
            //     {
            //         var name = context.Name;
            //         while (name.Length < 20)
            //             name += ' ';
            //         Console.WriteLine($"{name}\t{string.Join(',', context.Weights.Select(w => (w * context.RingWeight).ToString("+0.0;-0.0")))}");
            //     }
            // }

            if (contexts.Any())
            {
                for (var i = 0; i < this.Steps; i++)
                {
                    combined.Weights[i] = contexts.Sum(c => c.Weights[i] * c.RingWeight);
                }

                var maxIndex = 0;
                var minIndex = 0;

                for (var i = 0; i < this.Steps; i++)
                {
                    if (combined.Weights[i] > combined.Weights[maxIndex])
                    {
                        maxIndex = i;
                    }
                    if (combined.Weights[i] < combined.Weights[minIndex])
                    {
                        minIndex = i;
                    }
                }



                if (CanBoost && (SensorFleets.MyFleet?.Ships.Count ?? 0) > BoostThreshold && (combined.Weights[maxIndex] < BoostDangerThreshold || (SensorFleets.MyFleet?.Ships.Count ?? 0) > 108))
                {
                    Boost();
                }

                this.MidBad = combined.Weights[maxIndex] / 2.0f + combined.Weights[minIndex] / 2.0f;

                if (CanShoot)
                {
                    var target = FleetTargeting.ChooseTarget()
                                 ?? AbandonedTargeting.ChooseTarget()
                                 ?? FishTargeting.ChooseTarget();

                    if (target != null)
                    {
                        var     fff    = target;
                        Vector2 sp     = fff.Position - this.Position;
                        var     angleg = (int)(MathF.Atan2(sp.Y, sp.X) / MathF.Atan2(0.0f, -1.0f) / 2.0f * Steps);
                        if (true)//combined.Weights[((angleg)%Steps+Steps)%Steps]>combined.Weights[minIndex])
                        {
                            ShootAt(sp + this.Position);
                        }
                    }
                    else
                    {
                        if (SensorFleets.MyFleet != null)
                        {
                            ShootAt(SensorFleets.MyFleet.Momentum);
                        }
                    }
                }
            }



            SteerAngle(angle);

            return(Task.FromResult(0));
        }