/// <summary> /// Method the updates the enemy dictionary based on new scan data for a scanned robot. /// </summary> /// <param name="scannedRobotEvent">The scanned robot event containing data about the scanned robot.</param> private void UpdateEnemyDictionary(ScannedRobotEvent scannedRobotEvent) { var name = scannedRobotEvent.Name; // Check if data entry exists for the scanned robot if (enemyDictionary.ContainsKey(name)) { // Data entry exists => Update the current entry with new scanned data RobotData scannedRobot = enemyDictionary[name]; scannedRobot.Update(scannedRobotEvent, this); } else { // No data entry exists => Create a new data entry for the scanned robot RobotData scannedRobot = new RobotData(scannedRobotEvent, this); // Put the new data entry into the enemy dictionary enemyDictionary.Add(name, scannedRobot); } // Change the access order for the robot name, so the name is moved to, or added as the last entry if (accessedEnemyList.Contains(name)) { accessedEnemyList.Remove(name); } accessedEnemyList.Add(name); }
public double TargetAngle() { ScannedRobotEvent _target = blackBoard.lastScannedRobotEvent; if (_target == null) { return(0); } double _angle = blackBoard.robot.Heading + _target.Bearing % 360; Vector2 robot = new Vector2(Convert.ToInt32(blackBoard.robot.X), Convert.ToInt32(blackBoard.robot.Y)); Vector2 enemyBot = new Vector2(Convert.ToInt32(blackBoard.robot.X + Math.Sin(_angle) * _target.Distance), Convert.ToInt32(blackBoard.robot.Y + Math.Cos(_angle) * _target.Distance)); Vector2 result = robot * enemyBot; double dotResult1 = (robot.X * robot.Y) + (enemyBot.X * enemyBot.Y); double mag1 = Math.Sqrt(Math.Pow(robot.X, 2) + Math.Pow(robot.Y, 2)); double mag2 = Math.Sqrt(Math.Pow(enemyBot.X, 2) + Math.Pow(enemyBot.Y, 2)); double finalResult = Math.Cos(dotResult1 / (mag1 * mag2)); if (_angle < -180) { _angle += 360; } blackBoard.robot.Out.WriteLine("I scanned robot: " + enemyBot.X + "X " + enemyBot.Y + " Y"); return(_angle); }
private void FireOnTheWayToMedKit(ScannedRobotEvent e) { var ev = 8; var power = GetBulletPower(e); var absBearing = e.BearingRadians + HeadingRadians; _lastEnemyEnergy = e.Energy; var enemyLocation = Helper.GetProjection(X, Y, absBearing, e.Distance); var distToMed = Helper.GetDistance(X, Y, _lastMedPoint.X, _lastMedPoint.Y); var distFromEnemyToMed = Helper.GetDistance(enemyLocation.X, enemyLocation.Y, _lastMedPoint.X, _lastMedPoint.Y); var lam = Helper.GetAbsBearingInRadian(X, Y, _lastMedPoint.X, _lastMedPoint.Y) - Helper.GetAbsBearingInRadian(X, Y, enemyLocation.X, enemyLocation.Y); var sinB = distToMed / Math.Max(0.0001, distFromEnemyToMed) * Math.Sin(lam); var sinA = ev / Helper.GetBulletVelocity(power) * sinB; var gunAdjust = absBearing + Math.Asin(sinA) - GunHeadingRadians; SetTurnGunRightRadians(gunAdjust); if (GunHeat <= 0 && gunAdjust < Math.Atan2(0.5 * _radius, e.Distance)) { var fireBullet = SetFireBullet(power); } }
/// <summary> /// onScannedRobot: We have a target. Go get it. /// </summary> public override void OnScannedRobot(ScannedRobotEvent e) { // Calculate exact location of the robot double absoluteBearing = Heading + e.Bearing; double bearingFromGun = Utils.NormalRelativeAngleDegrees(absoluteBearing - GunHeading); // If it's close enough, fire! if (Math.Abs(bearingFromGun) <= 3) { TurnGunRight(bearingFromGun); // We check gun heat here, because calling Fire() // uses a turn, which could cause us to lose track // of the other robot. if (GunHeat == 0) { Fire(Math.Min(3 - Math.Abs(bearingFromGun), Energy - .1)); } } else { // otherwise just set the gun to turn. // Note: This will have no effect until we call scan() TurnGunRight(bearingFromGun); } // Generates another scan event if we see a robot. // We only need to call this if the gun (and therefore radar) // are not turning. Otherwise, scan is called automatically. if (bearingFromGun == 0) { Scan(); } }
private void OnEnemyFired(ScannedRobotEvent e, Operations op) { if (rnd.NextDouble() > 200 / e.Distance) { op.Direction = -op.Direction; } }
public override void OnScannedRobot(ScannedRobotEvent e) { double RadarTurn = Heading + e.Bearing - RadarHeading; SetTurnRightRadians(RadarTurn); SetAhead(50); }
/// <summary> /// Zorgt ervoor dat hij dicht genoeg bij het doelwit is maar niet zo dichtbij dat hij er tegen aanknalt /// </summary> /// <param name="e"></param> public void StayCloseToTarget(ScannedRobotEvent e) { // Rij richting doelwit als hij er te ver vandaan is if (e.Distance > 150) { blackBoard.gunTurnAmt = Utils.NormalRelativeAngleDegrees(e.Bearing + (Heading - RadarHeading)); SetTurnGunRight(blackBoard.gunTurnAmt); TurnRight(e.Bearing); Ahead(e.Distance - 140); return; } // Doelwit is dichtbij blackBoard.gunTurnAmt = Utils.NormalRelativeAngleDegrees(e.Bearing + (Heading - RadarHeading)); TurnGunRight(blackBoard.gunTurnAmt); Fire(3); // Rij terug als hij te dichtbij is if (e.Distance < 100) { if (e.Bearing > -90 && e.Bearing <= 90) { Back(40); } else { Ahead(40); } } }
public void SetEnemyData(ScannedRobotEvent newEnemyData, Point2D newPosition) { // First we set the stuff that depends on last updates' values: long deltaTime = newEnemyData.Time - Time; TurnRateRadians = Utils.NormalRelativeAngle(newEnemyData.HeadingRadians - HeadingRadians) / deltaTime; Acceleration = (newEnemyData.Velocity - Velocity) / deltaTime; // General data: Time = newEnemyData.Time; // Compared-to-us data: BearingRadians = newEnemyData.BearingRadians; Distance = newEnemyData.Distance; // Enemy specific data: Name = newEnemyData.Name; Energy = newEnemyData.Energy; Position = newPosition; Velocity = newEnemyData.Velocity; HeadingRadians = newEnemyData.HeadingRadians; //La til en LockOn, som blir true vær gang radaren har gått over motstanderne. LockOn = true; }
//When the robot sees another public override void OnScannedRobot(ScannedRobotEvent evnt) { /* * double angleToEnemy = Robocode.Util.Utils.ToRadians(GunHeading) + evnt.BearingRadians; * double radarTurn = Robocode.Util.Utils.NormalRelativeAngle(angleToEnemy - Robocode.Util.Utils.ToRadians(RadarHeading)); * double extraTurn = Math.Min(Math.Atan(36.0 / evnt.Distance), Rules.RADAR_TURN_RATE_RADIANS); * * radarTurn += (radarTurn < 0 ? -extraTurn : extraTurn); * TurnRadarRight(Robocode.Util.Utils.ToRadians(radarTurn)); */ /* * if (GunHeading < RadarHeading) * { * double diff = RadarHeading - GunHeading; * TurnGunRight(diff); * TurnRadarLeft(diff); * } * else * { * double diff = GunHeading - RadarHeading; * TurnGunLeft(diff); * TurnRadarRight(diff); * } */ System.Pr Fire(0.1); }
///Atirar //Atira ao Scanear um Robo public override void OnScannedRobot(ScannedRobotEvent e) { //Atira Fire(3); //Trava o Tiro no Oponente se ele ficar parado Scan(); }
// Robot event handler, when the robot sees another robot public override void OnScannedRobot(ScannedRobotEvent e) { //let each handler to handle onScaned event to build up complete data for all tick foreach (IHandleScanedRobot handleScanedRobot in handlers) { handleScanedRobot.HandleScanedRobot(this, e, lastScannedRobotEvent, operations, battleEvents); } if (tickcount == 0) { tickcount = minticks + (int)rnd.NextDouble() * ticksRange; var results = handlers.Select( handler => new { Evaludation = (int)handler.Evaluate(this, e, battleEvents), Handler = handler }) .OrderBy(item => item.Evaludation); var topones = results.Where(result => result.Evaludation == results.First().Evaludation); var choosen = topones.ElementAt((int)Math.Floor(rnd.NextDouble() * topones.Count())).Handler; currentHandler = choosen; } else { tickcount--; } ApplyOperations(currentHandler.HandleScanedRobot(this, e, lastScannedRobotEvent, operations, battleEvents)); lastScannedRobotEvent = e; }
private double getFutureRat(ScannedRobotEvent e) { double abshearing = HeadingRadians + e.BearingRadians; double rat = Math.Sin(e.HeadingRadians - abshearing); return(rat); }
private double getEnermyFutureX(double x, double time, ScannedRobotEvent e) { double futureX = 0; if (e.HeadingRadians < 0) //going left { if (e.HeadingRadians <= Math.PI / 2) { futureX = x - Math.Cos(e.HeadingRadians + Math.PI / 2) * e.Velocity * time; } else if (e.HeadingRadians > Math.PI / 2) { futureX = x - Math.Cos((e.HeadingRadians + Math.PI / 2) * -1) * e.Velocity * time; } } if (e.HeadingRadians > 0) //going right { if (e.HeadingRadians <= Math.PI / 2) { futureX = x + Math.Cos(Math.PI / 2 - e.HeadingRadians) * e.Velocity * time; } else if (e.HeadingRadians > Math.PI / 2) { futureX = x + Math.Cos(e.HeadingRadians - Math.PI / 2) * e.Velocity * time; } } return(futureX); }
private double getEnermyX(double absbearing, ScannedRobotEvent e) { double enermyX = 0; if (absbearing < 0) // enermy on the left { if (absbearing <= Math.PI / 2) { enermyX = X - Math.Cos(absbearing + Math.PI / 2) * e.Distance; } else if (absbearing > Math.PI / 2) { enermyX = X - Math.Cos(absbearing + Math.PI / 2 * -1) * e.Distance; } } if (absbearing > 0) //engermy on the right { if (absbearing <= Math.PI / 2) { enermyX = X + Math.Cos(Math.PI / 2 - absbearing) * e.Distance; } else if (absbearing > Math.PI / 2) { enermyX = X + Math.Cos(absbearing - Math.PI / 2) * e.Distance; } } return(enermyX); }
public void Ram(ScannedRobotEvent e, double firePower) { moveDirection = 1; double absbearing = Utils.NormalRelativeAngle(HeadingRadians + e.BearingRadians); double bulletSpeed = 20 - firePower * 3; double enermyHeading = Utils.NormalRelativeAngle(e.HeadingRadians); double enermyX = getEnermyX(absbearing, e); double enermyY = getEnermyY(absbearing, e); long time = (long)(e.Distance / bulletSpeed); double enermyFutureX = getEnermyFutureX(enermyX, time, e); double enermyFutureY = getEnermyFutureY(enermyY, time, e); double futureBearing = Utils.NormalRelativeAngle(getFutureBearing(enermyFutureX, enermyFutureY) - HeadingRadians); futureBearing = futureBearing > 3.5 ? 0 : e.Velocity * getFutureRat(e); double gunTurnAmount; SetTurnRadarLeftRadians(RadarTurnRemainingRadians); gunTurnAmount = Utils.NormalRelativeAngle(absbearing - GunHeadingRadians + futureBearing / 16); SetTurnGunRightRadians(gunTurnAmount); if (Energy > firePower && GunHeat == 0 && e.Distance < targetDist) { SetFire(firePower); } SetTurnRightRadians(Utils.NormalRelativeAngle(e.BearingRadians)); SetAhead((e.Distance + 500) * moveDirection); }
public override void OnScannedRobot(ScannedRobotEvent e) { double absoluteBearing = HeadingRadians + e.BearingRadians; PointF myLocation = new PointF((float)X, (float)Y); PointF predictedLocation = projectMotion(myLocation, absoluteBearing, e.Distance); double predictedHeading; double enemyTurnRate = -Utils.NormalRelativeAngle(expectedHeading - (predictedHeading = expectedHeading = e.HeadingRadians)); double bulletPower = Math.Min(e.Distance < 250 ? 500 / e.Distance : 200 / e.Distance, 3); int time = 0; while ((time++) * (20 - (3 * bulletPower)) < myLocation.Distance(predictedLocation) - 18) { predictedHeading += (enemyTurnRate / 3); predictedLocation = projectMotion(predictedLocation, predictedHeading, e.Velocity); if (!new RectangleF(18, 18, 764, 564).Contains(predictedLocation)) { break; } } double maxValue = Double.MinValue; double angle = 0; do { double value = Math.Abs(Math.Cos(Utils.NormalRelativeAngle(absoluteBearing - angle))) * e.Distance / 150; PointF testedLocation = projectMotion(myLocation, angle, 8); value -= testedLocation.Distance(predictedLocation); value -= testedLocation.Distance(new PointF(400, 300)) / 3; if (!new RectangleF(30, 30, 740, 540).Contains(testedLocation)) { value -= 10000; } if (value > maxValue) { maxValue = value; double turnAngle = angle - HeadingRadians; SetAhead(Math.Cos(turnAngle) > 0 ? 100 : -100); SetTurnRightRadians(Math.Tan(turnAngle)); } } while ((angle += 0.01) < Math.PI * 2); MaxVelocity = (Math.Abs(TurnRemaining) < 30 ? 8 : 8 - Math.Abs(TurnRemaining / 30)); double gunTurn = Utils.NormalRelativeAngle(Math.Atan2(predictedLocation.X - myLocation.X, predictedLocation.Y - myLocation.Y) - GunHeadingRadians); SetTurnGunRightRadians(gunTurn); if ((Math.Abs(gunTurn) < Math.PI / 9) && (GunHeat == 0.0)) { SetFire(bulletPower); } SetTurnRadarRightRadians(2 * Utils.NormalRelativeAngle(absoluteBearing - RadarHeadingRadians)); }
public override void onScannedRobot(ScannedRobotEvent @event) { this.fire(0.5); this.ahead(5); this.fire(0.5); this.fire(0.5); }
public void Update() { var myLocation = new Vector(0d, 0d); const double myHeading = 0; const string name = ""; const double energy = 100d; const double bearing = 0d; const double distance = 100d; const double heading = 90d; var mockEvent = new ScannedRobotEvent(name, energy, bearing, distance, heading * Math.PI / 180d, Rules.MAX_VELOCITY); var mockContext = new Mock <IContext>(); mockContext.Setup(mock => mock.MyLocation).Returns(myLocation); mockContext.Setup(mock => mock.MyHeading).Returns(myHeading); var enemy = new Enemy(mockContext.Object, mockEvent); var expectedLocation = myLocation + new Vector(distance, new Angle(myHeading + bearing)); AssertEqualVectors(expectedLocation, enemy.Location); Assert.AreEqual(energy, enemy.Energy); AssertEqualVectors(expectedLocation - myLocation, enemy.Direct); AssertEqualVectors(myLocation - expectedLocation, enemy.EnemyDirect); Assert.AreEqual(heading, enemy.Heading.Degrees); }
/// <summary> /// Zoek nauwkeurig en schiet als dat kan /// </summary> /// <param name="e"></param> void ScanStealthy(ScannedRobotEvent e) { // Bepaal de positie van de gespotte robot double absoluteBearing = Heading + e.Bearing; double bearingFromGun = Utils.NormalRelativeAngleDegrees(absoluteBearing - GunHeading); // Schiet als hij dichtbij is if (Math.Abs(bearingFromGun) <= 3) { TurnGunRight(bearingFromGun); // Schiet alleen als dat kan if (GunHeat == 0) { Fire(Math.Min(3 - Math.Abs(bearingFromGun), Energy - .1)); } } else { TurnGunRight(bearingFromGun); } if (bearingFromGun == 0) { Scan(); } }
public static Point2D FindTargetPosition(this Garics robot, ScannedRobotEvent e) { var angle = robot.HeadingRadians + e.BearingRadians; //TODO this takes a lot of negatives. Find out what's going on. return(new Point2D(robot.PositionVector - Vector2DHelpers.VectorFromAngle(-angle - Math.PI / 2, e.Distance))); }
public Confidence Evaluate(AdvancedRobot robot, ScannedRobotEvent e, BattleEvents battleEvents) { Confidence confidence = Confidence.DonotBlameMeIfILoose; if (e.Distance >= 200) { if (robot.Energy < e.Energy) { confidence = Confidence.DesignedForThis; } else { confidence = Confidence.CanHandleIt; } } else { if (robot.Energy < e.Energy) { confidence = Confidence.TryMe; } else { confidence = Confidence.DonotBlameMeIfILoose; } } return(confidence); }
/// <summary> /// This method is called by the game whenever our robot has scanned another robot by turning the radar. /// Note: Our radar is turning around forever at maximum speed, so this event is called as soon as the /// radar "hits" another robot. /// </summary> /// <param name="scannedRobotEvent">The scanned robot event containing data about the scanned robot.</param> public override void OnScannedRobot(ScannedRobotEvent scannedRobotEvent) { // Exit this method, if the scanned robot is another sentry robot if (scannedRobotEvent.IsSentryRobot) { return; } // Get the distance from our robot to the scanned robot double distance = scannedRobotEvent.Distance; // Calculate the angle in radians to the scanned robot. // Angle = our robot's heading (angle) + the bearing (delta angle) to the scanned robot. double angle = HeadingRadians + scannedRobotEvent.BearingRadians; // Prepare an entry with scanned robot data that we can store in our scanned data map ScannedRobotData robotData = new ScannedRobotData(); // Store the name of the scanned robot robotData.name = scannedRobotEvent.Name; // Store the time when the robot was scanned robotData.time = scannedRobotEvent.Time; // Calculate and store the x coordinate of the scanned robot (using the Robocode coordinate system) robotData.x = X + Math.Sin(angle) * distance; // Calculate and store the y coordinate of the scanned robot (using the Robocode coordinate system) robotData.y = Y + Math.Cos(angle) * distance; // Store the entry of scanned robot entry in our map over scanned robot data. // We use the name of the robot as the key for accessing the scanned data for that particular robot later scannedRobotData.Remove(robotData.name); scannedRobotData.Add(robotData.name, robotData); }
public Operations HandleScanedRobot(AdvancedRobot robot, ScannedRobotEvent e, ScannedRobotEvent previousScaned, Operations operations) { var calculatedParams = new CalculatedParams(robot, e); var newOperations = operations.Clone(); if (previousScaned != null && previousScaned.Energy > e.Energy) { OnEnemyFired(e, newOperations); } double turn = calculatedParams.AbsoluteBearing + Math.PI / 2; turn -= Math.Max(0.5, (1 / e.Distance) * 100) * newOperations.Direction; newOperations.TurnRightRadians = Utils.NormalRelativeAngle(turn - robot.HeadingRadians); //This line makes us slow down when we need to turn sharply. newOperations.MaxVelocity = 400 / robot.TurnRemaining; newOperations.Ahead = 100 * newOperations.Direction; if (newOperations.BulletPower.HasValue) { newOperations.TurnGunRightRadians = Utils.NormalRelativeAngle( GetCircularTargeting(robot, e, previousScaned != null ? previousScaned.HeadingRadians : 0, newOperations.BulletPower.Value, calculatedParams) - robot.GunHeadingRadians); } newOperations.TurnRadarRightRadians = Utils.NormalRelativeAngle(calculatedParams.AbsoluteBearing - robot.RadarHeadingRadians) * 2; return(newOperations); }
public override void OnScannedRobot(ScannedRobotEvent e) { Fire(1); currentState.DistanceToEnemy = e.Distance; currentState.EnemyEnergy = e.Energy; currentState.EnemyVelocity = e.Velocity; }
private double GetCircularTargeting(AdvancedRobot robot, ScannedRobotEvent e, double lastHeadingRadians, double power, CalculatedParams calculated) { //Finding the heading and heading change. double enemyHeading = e.HeadingRadians; double enemyHeadingChange = enemyHeading - lastHeadingRadians; /*This method of targeting is know as circular targeting; you assume your enemy will * keep moving with the same speed and turn rate that he is using at fire time.The * base code comes from the wiki. */ double deltaTime = 0; double predictedX = robot.X + e.Distance * Math.Sin(calculated.AbsoluteBearing); double predictedY = robot.Y + e.Distance * Math.Cos(calculated.AbsoluteBearing); double speed = Utility.GetBulletSpeed(power); while ((++deltaTime) * speed < Math.Sqrt(Math.Pow(robot.X - predictedX, 2) + Math.Pow(robot.Y - predictedY, 2))) { //Add the movement we think our enemy will make to our enemy's current X and Y predictedX += Math.Sin(enemyHeading) * e.Velocity; predictedY += Math.Cos(enemyHeading) * e.Velocity; //Find our enemy's heading changes. enemyHeading += enemyHeadingChange; //If our predicted coordinates are outside the walls, put them 18 distance units away from the walls as we know //that that is the closest they can get to the wall (Bots are non-rotating 36*36 squares). predictedX = Math.Max(Math.Min(predictedX, robot.BattleFieldWidth - 18), 18); predictedY = Math.Max(Math.Min(predictedY, robot.BattleFieldHeight - 18), 18); } //Find the bearing of our predicted coordinates from us. return(Utils.NormalAbsoluteAngle(Math.Atan2(predictedX - robot.X, predictedY - robot.Y))); }
/// <summary> /// onScannedRobot: Fire hard! /// </summary> public override void OnScannedRobot(ScannedRobotEvent e) { if (e.Name.IndexOf("HogPile") < 0) { Bot = new BotState(this, e); int turns = (int)(e.Distance / Rules.GetBulletSpeed(Rules.MAX_BULLET_POWER)); ProjectedLocation = Bot.GetProjectedLocation(turns, 2.0); double projHeading = Geometry.MakePoint(X, Y).Heading(ProjectedLocation); double gunBearing = Utils.NormalRelativeAngleDegrees(projHeading - GunHeading); //double gunBearing = Utils.NormalRelativeAngleDegrees(Heading + e.Bearing - GunHeading); double radarBearing = Utils.NormalRelativeAngleDegrees(Heading + e.Bearing - RadarHeading); //Out.WriteLine("Distance: {0}, Turn: {1}, Projected: {2},{3}, Heading: {4}, GunBearing: {5}", e.Distance, turns, ProjectedLocation.X, ProjectedLocation.Y, projHeading, gunBearing); if (radarBearing > 0) { RadarClockwise = true; } else { RadarClockwise = false; } SetTurnRadarRight(radarBearing * 2); SetTurnGunRight(gunBearing); SetTurnRight(e.Bearing); SetAhead(e.Distance); //if (distance > 100) ahead(distance/3); // if (distance < 80) back(20); } }
/// <summary> /// Fire when we see a robot /// </summary> public override void OnScannedRobot(ScannedRobotEvent e) { // demonstrate feature of debugging properties on RobotDialog DebugProperty["lastScannedRobot"] = e.Name + " at " + e.Bearing + " degrees at time " + Time; Fire(1); }
/// <summary> /// onScannedRobot: Fire hard! /// </summary> public override void OnScannedRobot(ScannedRobotEvent e) { if (!e.Name.ToLower().StartsWith("jury")) { Fire(3); } }
public override void OnScannedRobot(ScannedRobotEvent e) { SetTurnRadarLeft(RadarTurnRemaining); SetTurnGunRightRadians( Utils.NormalRelativeAngle(e.BearingRadians + HeadingRadians - GunHeadingRadians)); SetFire(3); }
private void DodgeMovement(ScannedRobotEvent e) { // Stay at right angles to the opponent TurnRight(e.Bearing + 90 - 30 * movementDirection); // If the bot has small energy drop, // assume it fired double changeInEnergy = previousEnergy - e.Energy; if (changeInEnergy > 0 && changeInEnergy <= 3) { // Dodge! movementDirection = -movementDirection; Ahead((e.Distance / 4 + 25) * movementDirection); } // When a bot is spotted, // sweep the gun and radar gunDirection = -gunDirection; TurnGunRight(360 * gunDirection); // Fire directly at target Fire(2); // Track the energy level previousEnergy = e.Energy; }
/// <summary> /// Method that updates the direction of the radar based on new scan data for a scanned robot. /// </summary> /// <param name="scannedRobotEvent">The scanned robot event containing data about the scanned robot.</param> private void UpdateScanDirection(ScannedRobotEvent scannedRobotEvent) { // Gets the name of the scanned robot var scannedRobotName = scannedRobotEvent.Name; // Change the scanning direction if and only if we have no record for the oldest scanned // robot or the scanned robot IS the oldest scanned robot (based on the name) AND the enemy // dictionary contains scanned data entries for ALL robots (the size of the enemy dictionary is equal to // the number of opponent robots found by calling the getOthers() method). if ((oldestScanned == null || scannedRobotName.Equals(oldestScanned.name)) && accessedEnemyList.Count == Others) { // Get the oldest scanned robot data from our LinkedHashMap, where the first value // contains the oldest accessed entry, which is the robot we need to get. string oldestScannedName = accessedEnemyList[0]; RobotData oldestScannedRobot = enemyDictionary[oldestScannedName]; // Get the recent scanned position (x,y) of the oldest scanned robot double x = oldestScannedRobot.scannedX; double y = oldestScannedRobot.scannedY; // Get the heading of our robot double ourHeading = RadarHeadingRadians; // Calculate the bearing to the oldest scanned robot. // The bearing is the delta angle between the heading of our robot and the other robot, // which can be a positive or negative angle. double bearing = BearingTo(ourHeading, x, y); // Update the scan direction based on the bearing. // If the bearing is positive, the radar will be moved to the right. // If the bearing is negative, the radar will be moved to the left. scanDir = bearing; } }
public override void onScannedRobot(ScannedRobotEvent @event) { GotTarget = true; this.fire(0.5); }