Beispiel #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));
        }
Beispiel #2
0
        public ContextTurret()
        {
            ContextBehaviors.Add(Navigation = new NavigateToPoint(this)
            {
                BehaviorWeight = 0.00f
            });
            ContextBehaviors.Add(Efficiency = new Efficiency(this)
            {
                BehaviorWeight = 1f, MaximumAngle = MathF.PI / 4
            });
            ContextBehaviors.Add(Dodge0 = new Dodge(this)
            {
                LookAheadMS = 250, BehaviorWeight = 2
            });
            ContextBehaviors.Add(Dodge1 = new Dodge(this)
            {
                LookAheadMS = 500, BehaviorWeight = 2
            });
            ContextBehaviors.Add(Dodge2 = new Dodge(this)
            {
                LookAheadMS = 1000, BehaviorWeight = 2
            });
            ContextBehaviors.Add(Separation = new Separation(this)
            {
                LookAheadMS = 500, BehaviorWeight = 0f
            });
            ContextBehaviors.Add(StayInBounds = new StayInBounds(this)
            {
                LookAheadMS = 1000, BehaviorWeight = 1f
            });

            Navigation.TargetPoint = new Vector2(0, 0);
            Steps = 16;
        }
Beispiel #3
0
        public MadBot()
        {
            FleetTargeting     = new FleetTargeting(this);
            AbandonedTargeting = new AbandonedTargeting(this);
            FishTargeting      = new FishTargeting(this);
            ContextBehaviors.Add(Navigation = new NavigateToPoint(this)
            {
                BehaviorWeight = 1.0f
            });
            // Behaviors.Add(Efficiency = new Efficiency(this) { BehaviorWeight = 0.0f });
            // Behaviors.Add(Dodge0 = new Dodge(this) { LookAheadMS = 100, BehaviorWeight = 2 });
            // Behaviors.Add(Dodge1 = new Dodge(this) { LookAheadMS = 200, BehaviorWeight = 2 });
            // Behaviors.Add(Dodge2 = new Dodge(this) { LookAheadMS = 300, BehaviorWeight = 2 });
            for (int m = 000; m < 2000; m += 50)
            {
                ContextBehaviors.Add(new DogeWow(this)
                {
                    LookAheadMS = m + 50, BehaviorWeight = 1
                });
            }
            ContextBehaviors.Add(Separation = new Separation(this)
            {
                LookAheadMS = 500, BehaviorWeight = 2.0f
            });
            ContextBehaviors.Add(StayInBounds = new StayInBounds(this)
            {
                LookAheadMS = 1000, BehaviorWeight = 10f
            });

            Sensors.Add(SensorCTF = new SensorCTF(this));

            Navigation.TargetPoint = new Vector2(0, 0);
            Steps = 16;
        }
Beispiel #4
0
        private void Behave()
        {
            var contexts = ContextBehaviors.Select(b => b.Behave(Steps)).ToList();

            (var finalRing, var angle, var boost) = ContextRingBlending.Blend(contexts, false);
            BlendedRing = finalRing;
            SteerAngle(angle);
        }
Beispiel #5
0
        public CTFBot()
        {
            ContextBehaviors.Add(Navigation = new NavigateToPoint(this)
            {
                BehaviorWeight = 0.1f
            });
            ContextBehaviors.Add(Efficiency = new Efficiency(this)
            {
                BehaviorWeight = 0.1f
            });
            ContextBehaviors.Add(Dodge0 = new Dodge(this)
            {
                LookAheadMS = 250, BehaviorWeight = 2
            });
            ContextBehaviors.Add(Dodge1 = new Dodge(this)
            {
                LookAheadMS = 500, BehaviorWeight = 2
            });
            ContextBehaviors.Add(Dodge2 = new Dodge(this)
            {
                LookAheadMS = 1000, BehaviorWeight = 2
            });
            ContextBehaviors.Add(Separation = new Separation(this)
            {
                LookAheadMS = 500, BehaviorWeight = 0f
            });
            ContextBehaviors.Add(StayInBounds = new StayInBounds(this)
            {
                LookAheadMS = 200, BehaviorWeight = 0.3f
            });

            Sensors.Add(SensorCTF = new SensorCTF(this));

            Navigation.TargetPoint = Vector2.Zero;
            Steps = 16;
        }
Beispiel #6
0
        private void Behave()
        {
            Random r = new Random();

            //this.JumpMS=(int)(r.NextDouble()*100.0)+100;
            this.Steps = 8;
            // System.Console.WriteLine(this.Steps);
            if (this.SensorFleets.MyFleet != null)
            {
                var teamMode = this.HookComputer.Hook.TeamMode;
                this.DangerousBullets = this.SensorBullets.VisibleBullets
                                        .Where(b => b.Group.Owner != this.FleetID)
                                        .Where(b => !teamMode || b.Group.Color != this.Color)
                                        .ToList();
                var baseS = new TreeState(0, this.SensorFleets.MyFleet, this);
                (var ddd, var qq) = this.Score(baseS);
                baseS.Score       = ddd;
                if (qq < -0.5f)
                {
                    //Boost();
                }
                if (qq <= -1.0f)
                {
                    //Boost();
                    System.Console.WriteLine("OOOF: " + qq.ToString());
                }
                var searchPaths = new List <TreeState> {
                    baseS
                };
                var newSearchPaths = new List <TreeState>();

                for (var i = 0; i < this.Depth; i++)
                {
                    newSearchPaths = new List <TreeState>();
                    for (int j = 0; j < Math.Min(searchPaths.Count, MaxSearch); j++)
                    {
                        if (searchPaths[j].Fleet.Ships.Count > 0 && searchPaths[j].Children.Count < 1)
                        {
                            for (int k = 0; k < this.Steps; k++)
                            {
                                // if(searchPaths[j].Fleet.Ships.Count>0 && searchPaths[j].Children.Count<1){
                                var p = searchPaths[j].ProjectClone(JumpMS * (1 + i), ((float)k) * 360.0f / ((float)this.Steps), k >= this.Steps);
                                (var md, var xd) = this.Score(p);
                                p.Score          = md;
                                //if(p.Score>-1.0f){
                                newSearchPaths.Add(p);
                                //}
                            }
                        }
                        else
                        {
                            searchPaths.RemoveAt(j);
                            j--;
                        }
                    }
                    if (i == 0)
                    {
                        firstRow = newSearchPaths.ToList();
                    }

                    searchPaths = ((newSearchPaths.ToList()).OrderByDescending(p => p.Score + r.NextDouble() * 0.0f)).ToList();//.Take(i==0?Steps+1:MaxSearch).ToList();
                }
                var contexts = ContextBehaviors.Select(b => b.Behave(Steps)).ToList();
                (var finalRing, var angle, var boost) = ContextRingBlending.Blend(contexts, false);
                BlendedRing            = finalRing;
                (var bestp, var bestc) = baseS.bestChildScorePath();

                if (bestp.Last().Fleet.Ships.Count * 2 <= this.SensorFleets.MyFleet.Ships.Count && CanBoost)
                {
                    //Boost();
                    //System.Console.WriteLine("BOOST");
                }
                //Boost();
                //System.Console.WriteLine("SC: "+bestc+", Ships: "+bestp.Last().Fleet.Ships.Count);
                // System.Console.WriteLine(bestp.Select(x=>x.Angle).ToArray()[1]);

                Vector2 angleM = new Vector2(MathF.Cos(GameTime * 10.0f), MathF.Sin(GameTime * 10.0f));
                float   cangle = MathF.Atan2(angleM.Y, angleM.X);
                if (bestp.Count > 1)
                {
                    var bestD = bestp[1].Angle;                                       //bestp[1].Fleet.Center-this.SensorFleets.MyFleet.Center;
                    angleM = new Vector2(MathF.Cos(bestD), MathF.Sin(bestD)) * 20.0f; //+new Vector2(MathF.Cos(angle),MathF.Sin(angle))*1.0f;//-10.0f*this.SensorFleets.MyFleet.Center/this.SensorFleets.MyFleet.Center.Length();///((float)WorldSize);
                }


                // var Projections = DangerousBullets.Select(b => b.Position).ToList().Select(b=>(b-this.SensorFleets.MyFleet.Center).Length()).Concat(new List<float>{10000});

                if (bestp.Count > 1)
                {
                    SteerAngle(MathF.Atan2(angleM.Y, angleM.X));
                    PathV = bestp;
                    //System.Console.WriteLine(PathV.Count);
                }
            }
            else
            {
                //System.Console.WriteLine("NJJHDfbhjdsfgyhtdsgfhtyfgdsuygt");
            }
        }
Beispiel #7
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));
        }