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)); }
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); }
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"); } }
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)); }