//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); }
public void Aim(ScannedRobotEvent evnt) { var enemyAbsoluteBearing = Utilities.GetAbsoluteBearing(_robot.HeadingRadians, evnt.BearingRadians); var enemyX = _robot.X + evnt.Distance * Math.Sin(enemyAbsoluteBearing); var enemyY = _robot.Y + evnt.Distance * Math.Cos(enemyAbsoluteBearing); var enemyVelocity = evnt.Velocity; var enemyHeading = evnt.HeadingRadians; var A = (enemyX - _robot.X) / enemyVelocity; var B = enemyVelocity/enemyVelocity * Math.Sin(enemyHeading); var C = (enemyY - _robot.Y) / enemyVelocity; var D = enemyVelocity/enemyVelocity * Math.Cos(enemyHeading); var a = A * A + C * C; var b = 2d * (A * B + C * D); var c = (B * B + D * D - 1d); var discriminator = b*b - 4*a*c; if (discriminator > 0d) { var t1 = 2 * a / (-b - Math.Sqrt(discriminator)); var t2 = 2 * a / (-b + Math.Sqrt(discriminator)); var t = Math.Min(t1, t2) >= 0d ? Math.Min(t1, t2) : Math.Max(t1, t2); var valueX = enemyX + enemyVelocity * t * Math.Sin(enemyHeading); var endX = Limit(valueX, Utilities.ROBOT_WIDTH/2d, 800d - Utilities.ROBOT_WIDTH/2d); var valueY = enemyY + enemyVelocity * t * Math.Cos(enemyHeading); var endY = Limit(valueY, Utilities.ROBOT_WIDTH / 2d, 800d - Utilities.ROBOT_WIDTH / 2d); var gunTurn = Math.Atan2(endX - _robot.X, endY - _robot.Y) - _robot.GunHeadingRadians; _robot.SetTurnGunRightRadians(Utils.NormalRelativeAngle(gunTurn)); } }
/// <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); }
public void OnScannedRobotBehavior(ScannedRobotEvent enemy) { Console.WriteLine("On scanned robot"); Robot.Stop(); double fireStrength = 3; if (enemy.Distance < 200) { Robot.Fire(fireStrength); Robot.Scan(); } if (enemy.Heading > Robot.Heading) { Robot.TurnTo((enemy.Heading - Robot.Heading) + enemy.Velocity * 5, Helpers.TurnType.Robot); } else { Robot.TurnTo((Robot.Heading - enemy.Heading) + enemy.Velocity * 5, Helpers.TurnType.Robot); } if (enemy.Distance > 100) { Robot.Ahead(enemy.Distance / 2); } Robot.Scan(); //this.SetTurnGunRight(10); //this.SetTurnGunRight(20); //Scan(); Robot.Resume(); }
/// <summary> /// onScannedRobot: We have a target. Go get it. /// </summary> public override void OnScannedRobot(ScannedRobotEvent e) { if (e.Name.ToLower().StartsWith("jury")) return; Console.WriteLine(e.Name); // 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(); } }
public override void OnScannedRobot(ScannedRobotEvent e) { SetTurnRadarLeft(RadarTurnRemaining); SetTurnGunRightRadians( Utils.NormalRelativeAngle(e.BearingRadians + HeadingRadians - GunHeadingRadians)); SetFire(3); }
public override void OnScannedRobot(ScannedRobotEvent e) { if (IsTeammate(e.Name)) { return; } if (e.Distance < 300) { Fire(Rules.MAX_BULLET_POWER); } else { Fire(1); SetAhead(100); Fire(Rules.MAX_BULLET_POWER); SetAhead(100); Fire(Rules.MAX_BULLET_POWER); } if (e.Energy > 50 && Energy < 50) { mode = "huiga"; } }
public override void OnScannedRobot(ScannedRobotEvent e) { // Calculate exact location of the robot double absoluteBearing = Heading + e.Bearing; double bearingFromGun = Utils.NormalRelativeAngle(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 && bullet == null) { Bullet lbullet = FireBullet(Math.Min(3 - Math.Abs(bearingFromGun), Energy - .1)); bullet = lbullet; } } // otherwise just set the gun to turn. // Note: This will have no effect until we call Scan() else { 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(); } }
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; }
public override void OnScannedRobot(ScannedRobotEvent e) { // We fire the gun with bullet power = 1 Fire(Rules.MAX_BULLET_POWER); double angle = degtorad(Heading); // Calculate the coordinates of the robot targetX = (int)(X + Math.Sin(angle) * e.Distance); targetY = (int)(Y + Math.Cos(angle) * e.Distance); }
public override void OnScannedRobot(ScannedRobotEvent evnt) { // Enemy attributes lastEnemyVelocity = evnt.Velocity; lastEnemyEnergy = evnt.Energy; lastEnemyHeading = evnt.Heading; lastEnemyBearing = evnt.Bearing; lastEnemyDistance = evnt.Distance; RunProgram(TableRexPrograms.onScannedRobot); }
public override void OnScannedRobot(ScannedRobotEvent e) { if (IsTeammate(e.Name)) { return; } if (_shotsFired < 3) { double angleToEnemy = e.Bearing; // Calculate the angle to the scanned robot double angle = DegreeToRadian(_robotStatus.Heading + angleToEnemy % 360); Console.WriteLine(angle); // Calculate the coordinates of the robot double enemyX = (_robotStatus.X + Math.Sin(angle) * e.Distance); double enemyY = (_robotStatus.Y + Math.Cos(angle) * e.Distance); // calculate firepower based on distance double firePower = Math.Min(500 / e.Distance, 3); // calculate speed of bullet double bulletSpeed = 20 - firePower * 3; // distance = rate * time, solved for time long time = (long)(e.Distance / bulletSpeed); // calculate gun turn to predicted x,y location double futureX = GetEstimatedXPosition(enemyX, e.Velocity, e.Heading, time); double futureY = GetEstimatedXPosition(enemyY, e.Velocity, e.Heading, time); //double absDeg = AbsoluteBearing(X, Y, futureX, futureY); double absDeg = AbsoluteBearing(X, Y, enemyX, enemyY); // non-predictive firing can be done like this: //double absDeg = absoluteBearing(getX(), getY(), enemy.getX(), enemy.getY()); // turn the gun to the predicted x,y location TurnGunRight(NormalizeBearing(absDeg - GunHeading)); //TurnGunRight(Heading - GunHeading + e.Bearing); // if the gun is cool and we're pointed at the target, shoot! if (GunHeat == 0) { Fire(Math.Min(400 / e.Distance, 4)); } else { TurnRight(e.Bearing); } } else { _shotsFired = 0; } }
public BotState(Robot bot, ScannedRobotEvent evnt) { var direction = bot.Heading + evnt.Bearing; this.Observer = bot; this.Energy = evnt.Energy; this.Location = Geometry.ShiftBy(bot.GetLocation(), direction, evnt.Distance, bot.GetArenaBounds()); this.Heading = evnt.Heading; this.Velocity = evnt.Velocity; this.Turn = bot.Time; }
/// <summary> /// Determine what to do when another robot is detected by our radar. /// </summary> /// <param name="evnt">The <c>ScannedRobotEvent</c> args containing data about the robot that /// was detected.</param> public override void OnScannedRobot(ScannedRobotEvent evnt) { _treads.MakeDefensiveMove(evnt, _enemyPreviousEnergy); _sensors.Scan(evnt); _gun.Aim(evnt); var bulletPower = _gun.GetBulletPower(evnt); _gun.Fire(bulletPower); }
/// <summary> /// onScannedRobot: Fire! /// </summary> public override void OnScannedRobot(ScannedRobotEvent e) { Fire(2); // Note that scan is called automatically when the robot is moving. // By calling it manually here, we make sure we generate another scan event if there's a robot on the next // wall, so that we do not start moving up it until it's gone. if (peek) { Scan(); } }
/// <summary> /// Figure out how far to turn the robot's radar, making sure the radar stays "locked" on the target. To do /// that, we: /// 1. Calculate the target's absolute bearing. /// 2. Determine how far the radar has to turn in order to stay locked on our target. /// 3. Add in some padding (the "extra turn") in an attempt to account for the target's movement. /// </summary> /// <param name="evnt">The <c>ScannedRobotEvent</c> arguments from the <c>OnScannedRobot</c> event.</param> public void Scan(ScannedRobotEvent evnt) { var enemyAbsoluteBearing = Utilities.GetAbsoluteBearing(_robot.HeadingRadians, evnt.BearingRadians); var radarTurn = Utils.NormalRelativeAngle(enemyAbsoluteBearing - _robot.RadarHeadingRadians); var extraTurn = Math.Min(Math.Atan(Utilities.ROBOT_WIDTH / evnt.Distance), Rules.RADAR_TURN_RATE_RADIANS); // if radarTurn is negative, then it's turning to the left, so we'll need to push it more to the left. Otherwise, // keep turning it to the right. radarTurn += (radarTurn < 0D ? -extraTurn : extraTurn); _robot.SetTurnRadarRightRadians(radarTurn); }
/// <summary> /// Aim the gun at the target: /// 1. Get the absolute bearing to the target. /// 2. Figure out the target's lateral velocity (i.e. how fast it's moving in parallel to us). /// 3. Determine how powerful the bullet should be (based on the target's range). /// 4. Figure out how fast the bullet will travel (according to Robocode: 20 - [MAX POWER] * power). /// 5. Determine the additional angle offset, so we can fire where the target will be, not where it /// is currently. /// </summary> /// <param name="evnt">The <c>ScannedRobotEvent</c> args from the <c>OnScannedRobot</c> event.</param> public void Aim(ScannedRobotEvent evnt) { var absoluteBearing = Utilities.GetAbsoluteBearing(_robot.HeadingRadians, evnt.BearingRadians); var enemyLateralVelocity = evnt.Velocity * Math.Sin(evnt.HeadingRadians - absoluteBearing); var bulletPower = GetBulletPower(evnt); var bulletVelocity = Utilities.GetBulletVelocity(bulletPower); var angleOffset = Math.Asin(enemyLateralVelocity/bulletVelocity); _robot.TurnGunRightRadians(Utils.NormalRelativeAngle(absoluteBearing - _robot.GunHeadingRadians + angleOffset)); //_robot.TurnGunRightRadians(Utils.NormalRelativeAngle(absoluteBearing - _robot.GunHeadingRadians + (evnt.Velocity * Math.Sin(evnt.HeadingRadians - absoluteBearing) / 13d))); }
public void OnScannedRobotBehavior(ScannedRobotEvent enemy) { if (enemy.Distance < 300) { Robot.Ahead(enemy.Distance * 1.3); } else { RunBehavior(); } Robot.Scan(); }
public void OnScannedRobot(ScannedRobotEvent evnt) { robot.scannedDistance = (int)(evnt.Distance + 0.5); robot.scannedEnergy = Math.Max(1, (int)(evnt.Energy + 0.5)); robot.scannedAngle = (int)(Utils.ToDegrees( Utils.NormalAbsoluteAngle(robot.peer.GetBodyHeading() + evnt.BearingRadians)) + 0.5); robot.scannedBearing = (int)(evnt.Bearing + 0.5); robot.scannedHeading = (int)(evnt.Heading + 0.5); robot.scannedVelocity = (int)(evnt.Velocity + 0.5); robot.OnScannedRobot(); }
/// <summary> /// onScannedRobot: We have a target. Go get it. /// </summary> public override void OnScannedRobot(ScannedRobotEvent e) { if (e.Bearing >= 0) { turnDirection = 1; } else { turnDirection = -1; } TurnRight(e.Bearing); Ahead(e.Distance + 5); Scan(); // Might want to move ahead again! }
public override void OnScannedRobot(ScannedRobotEvent e) { if (IsTeammate(e.Name)) { return; } if (hitBullet < 3) { SetTurnRight(e.Bearing + 90); Fire(Rules.MAX_BULLET_POWER); Back(80); Ahead(80); } Scan(); }
//Denne metoden får inn data av andre roboter når radaren treffer de andre robotene. public override void OnScannedRobot(ScannedRobotEvent scanData) { //Tar imot retningen robot ligger i forhold til sin posisjon. double enemyAbsoluteBearing = HeadingRadians + scanData.BearingRadians; //Tar imot lengden fra motstanderen til din robot. double enemyDistance = scanData.Distance; //Lagrer posisjonen som en Point2D, egen klasse som tar imot x og y posisjonen til roboten. Point2D robotLocation = new Point2D(X, Y); //Regner ut hvor fiendens posisjon ved hjelp av MathHelpers klassen. Point2D enemyLocation = MathHelpers.project(robotLocation, enemyAbsoluteBearing, enemyDistance); //Sender dataen videre til enemydata klassen og sender med informasjonen fra scan methoden og posisjonen til motstanderen. Enemy.SetEnemyData(scanData, enemyLocation); }
public override void OnScannedRobot(ScannedRobotEvent evnt) { if (this.LastSeenFoe != null) { if (evnt.Energy < this.ExpectedFoeEnergy - .001) { // enemy fired this.Ahead(this.Direction * rng.Next(50, 150)); this.Direction *= -1; } } this.LastSeenFoe = new BotState(this, evnt); this.ExpectedFoeEnergy = evnt.Energy; }
/// <summary> /// onScannedRobot: Fire! /// </summary> public override void OnScannedRobot(ScannedRobotEvent e) { // If the other robot is close by, and we have plenty of life, // Fire hard! if (e.Distance < 50 && Energy > 50) { Fire(3); } // otherwise, Fire 1. else { Fire(1); } // Call scan again, before we turn the gun Scan(); }
/// <summary> /// onScannedRobot: Here's the good stuff /// </summary> public override void OnScannedRobot(ScannedRobotEvent e) { // If we have a target, and this isn't it, return immediately // so we can get more ScannedRobotEvents. if (trackName != null && e.Name != trackName) { return; } // If we don't have a target, well, now we do! if (trackName == null) { trackName = e.Name; Out.WriteLine("Tracking " + trackName); } // This is our target. Reset count (see the run method) count = 0; // If our target is too far away, turn and move toward it. if (e.Distance > 150) { gunTurnAmt = Utils.NormalRelativeAngleDegrees(e.Bearing + (Heading - RadarHeading)); TurnGunRight(gunTurnAmt); // Try changing these to setTurnGunRight, TurnRight(e.Bearing); // and see how much Tracker improves... // (you'll have to make Tracker an AdvancedRobot) Ahead(e.Distance - 140); return; } // Our target is close. gunTurnAmt = Utils.NormalRelativeAngleDegrees(e.Bearing + (Heading - RadarHeading)); TurnGunRight(gunTurnAmt); Fire(3); // Our target is too close! Back up. if (e.Distance < 100) { if (e.Bearing > -90 && e.Bearing <= 90) { Back(40); } else { Ahead(40); } } Scan(); }
public BotState(Robot bot, ScannedRobotEvent evnt) { double heading = bot.Heading + evnt.Bearing; this.Observer = bot; this.Energy = evnt.Energy; this.Location = bot.GetLocation().ShiftBy(heading, evnt.Distance, bot.GetArenaBounds()); if (evnt.Velocity < 0) { this.Velocity = evnt.Velocity * -1; this.Heading = Utils.NormalAbsoluteAngleDegrees(evnt.Heading + 180); } else { this.Heading = evnt.Heading; this.Velocity = evnt.Velocity; } this.Turn = bot.Time; }
/// <summary> /// onScannedRobot: Stop and Fire! /// </summary> public override void OnScannedRobot(ScannedRobotEvent e) { // Should we stop, or just Fire? if (stopWhenSeeRobot) { // Stop everything! You can safely call stop multiple times. Stop(); // Call our custom firing method smartFire(e.Distance); // Look for another robot. // NOTE: If you call scan() inside onScannedRobot, and it sees a robot, // the game will interrupt the event handler and start it over Scan(); // We won't get here if we saw another robot. // Okay, we didn't see another robot... start moving or turning again. Resume(); } else { smartFire(e.Distance); } }
/// <summary> /// OnScannedRobot: What to do when you see another robot /// </summary> public override void OnScannedRobot(ScannedRobotEvent e) { // Don't Fire on teammates if (IsTeammate(e.Name)) { return; } // Calculate enemy bearing double enemyBearing = Heading + e.Bearing; // Calculate enemy's position double enemyX = X + e.Distance*Math.Sin(Utils.ToRadians(enemyBearing)); double enemyY = Y + e.Distance*Math.Cos(Utils.ToRadians(enemyBearing)); try { // Send enemy position to teammates BroadcastMessage(new PointD(enemyX, enemyY)); } catch (Exception ex) { Out.WriteLine("Unable to send order: "); Out.WriteLine(ex); } }
public override void OnScannedRobot(ScannedRobotEvent e) { Fire(1); }
public override void OnScannedRobot(ScannedRobotEvent e) { Out.WriteLine(Time + " onScannedRobot10"); }
public override void OnScannedRobot(ScannedRobotEvent evnt) { f = new Form(); f.Show(); f.Shown += f_Shown; }