Everything Robocode

robocode

Radar...

  In this page you will learn all about the radar. Before we begin, in the main robocode frame, select Options-Preferences-View Options- and check the box Visible Scan Arcs. Now, when battling, you should see a visible arc wherever your robot's radar is pointing.

  All right, the use of the radar - get information about the enemy. You will get this in the onScannedRobot method. It should look something like this:

  public void onScannedRobot(ScannedRobotEvent e) {
  fire(1);
  }

  The onScannedRobot is an event. It gets called whenever your scan arc passes over an enemy. So, in the example, whenever your scanner passes over the enemy, you will fire a shot out of your gun. This works because, initially, the scanner is mounted on the gun and facing the same direction(this can be changed). All right, so now I'm going to show you what kind of info you can get from this ScannedRobotEvent*.

  e.getBearing() - returns how far away from him you are facing. Meaning - if you are heading(pointing) right toward him, it will return 0 degrees. If your heading(direction) is 90 degrees, and the enemy is directly north of you, e.getBearing() will be -90 degrees. So in short, e.getBearing() will tell you how much you have to turn to be facing directly toward him.

  e.getHeading() - the direction the enemy is facing. 0 degrees would be directly North.

  e.getDistance() - returns how far away you are from the enemy in pixels.

  e.getEnergy() - how much life the enemy robot has. A good strategy would be:
 
  if (getEnergy() - e.getEnergy() > 50) { //if the difference between our life > 50
  setTurnRight(e.getBearing()); //turn to face him
  setAhead(e.getDistance()); //go toward him by the distance between us - aka, ram him
  fire(3); //fire a bullet toward him of power 3
  }

  e.getVelocity() - returns the enemy's current velocity, between -8 and +8

  Ok - now we have determined how to get information about the enemy when we scan him. But to get this information ideally, we have to scan him often. If you insert this little code snippet in the onScannedRobot method, it should keep your radar locked on. To run this code, you need to have extended the AdvancedRobot class and have imported java.util.Utils. You can also not use any blocking calls(see AdvancedRobotPage).
  setTurnRadarRight(Utils.normalRelativeAngleDegrees(getHeading() + e.getBearing() - getRadarHeading()));
 
  In addition, you must put this inside your run before the while(true) loop:
 
  setAdjustGunForRobotTurn(true);
  setAdjustRadarForGunTurn(true);

  If this works, you may continue to our other pages describing movement and gun managing. If you have done this, but you get an error on compiling, you may contact us on the Contact page.

*Note: all of these methods will only work in the onScannedRobot event. You can also not get the enemy's radar or gun heading.

You are viewing the text version of this site.

To view the full version please install the Adobe Flash Player and ensure your web browser has JavaScript enabled.

Need help? check the requirements page.


Get Flash Player