public override void Run() { try { Console.WriteLine("START"); BodyColor = Color.Black; GunColor = Color.White; RadarColor = Color.White; CurrentPhase = RoboPhase.WallRush; RoboPhase changePhase = RoboPhase.UnknownPhase; IsAdjustGunForRobotTurn = true; while (true) { foreach (var enemies in KnownEnemies.Where(r => (Time - r.Value.Time) >= 30).ToArray()) { KnownEnemies.Remove(enemies.Key); } if (TargetEnemyName != null && !KnownEnemies.ContainsKey(TargetEnemyName)) { TargetEnemyName = null; } if (phases.ContainsKey(CurrentPhase)) { if (phases[CurrentPhase] is IAdvancedPhase) { IAdvancedPhase phase = (IAdvancedPhase)phases[CurrentPhase]; if (CurrentPhase != changePhase) { phase.ActivatePhase(changePhase); changePhase = CurrentPhase; Execute(); } phase.Tick(); if (CurrentPhase != changePhase) { Execute(); phase.DeactivatePhase(changePhase); } else { Execute(); } } else { changePhase = CurrentPhase; phases[CurrentPhase].Run(); Execute(); } } } } catch (Exception e) { exception = e; Console.WriteLine(e.GetType().Name); Console.WriteLine(e.Message ?? "Unkown"); throw e; } }
public Point GetLastTargetCoordinates(bool tryOptimize = false) { if (TargetEnemyName == null || !KnownEnemies.ContainsKey(TargetEnemyName)) { return(new Point()); } var lastScanStatus = KnownEnemies[TargetEnemyName]; if ((lastScanStatus?.Energy ?? 0) == 0) { lastScanStatus = null; } double?x = LastBulletHit?.Bullet?.X; double?y = LastBulletHit?.Bullet?.Y; if (KnownEnemies.ContainsKey(TargetEnemyName)) { lastScanStatus = KnownEnemies[TargetEnemyName]; if (LastBulletHit == null || lastScanStatus.Time > LastBulletHit.Time) { x = lastScanStatus.X; y = lastScanStatus.Y; } if (tryOptimize) { EnemyBot curEnemy = lastScanStatus; List <EnemyBot> interesting = new List <EnemyBot>(); for (var i = 0; i < 100; i++) { interesting.Add(curEnemy); if (!curEnemy.IsTarget) { break; } if (curEnemy.PreviousEntry == null) { break; } curEnemy = curEnemy.PreviousEntry; } var target = interesting.Select(i => new { Amount = interesting.Count(i2 => BoundCompare(i.X, i2.X, 10) && BoundCompare(i.Y, i2.Y, 10)), X = i.X, Y = i.Y }).ToArray(); if (target.Max(t => t.Amount) > 10) { x = target.OrderByDescending(t => t.Amount).FirstOrDefault()?.X; y = target.OrderByDescending(t => t.Amount).FirstOrDefault()?.Y; } } } return(new Point { X = x ?? 0, Y = y ?? 0 }); }