/** onScannedRobot: What to do when you see another robot */
 public void onScannedRobot(ScannedRobotEvent e) {
   if (isFriend(e.getName())) {
     return;
   }
   Enemy en;
   if (targets.containsKey(e.getName())) {
     en = (Enemy) targets.get(e.getName());
   } else {
     en = new Enemy();
     targets.put(e.getName(), en);
   }
   // the next line gets the absolute bearing to the point where the bot is
   double absbearing_rad = (getHeadingRadians() + e.getBearingRadians()) % (2 * PI);
   // this section sets all the information about our target
   en.name = e.getName();
   double h = normaliseBearing(e.getHeadingRadians() - en.heading);
   h = h / (getTime() - en.ctime);
   en.changehead = h;
   en.x = getX() + Math.sin(absbearing_rad) * e.getDistance(); // works out
   // the x
   // coordinate
   // of where
   // the
   // target is
   en.y = getY() + Math.cos(absbearing_rad) * e.getDistance(); // works out
   // the y
   // coordinate
   // of where
   // the
   // target is
   en.bearing = e.getBearingRadians();
   en.heading = e.getHeadingRadians();
   en.ctime = getTime(); // game time at which this scan was produced
   en.speed = e.getVelocity();
   en.distance = e.getDistance();
   en.live = true;
   if ((en.distance < target.distance) || (target.live == false)) {
     target = en;
   }
 }
 public void run() {
   targets = new Hashtable();
   target = new Enemy();
   target.distance = 100000;
   setBodyColor(Color.ORANGE);
   // the next two lines mean that the turns of the robot, gun and radar
   // are independant
   setAdjustGunForRobotTurn(true);
   setAdjustRadarForGunTurn(true);
   turnRadarRightRadians(2 * PI); // turns the radar right around to get a
   // view of the field
   while (true) {
     move();
     doFirePower(); // select the fire power to use
     doScanner(); // Oscillate the scanner over the bot
     doGun();
     out.println(target.distance); // move the gun to predict where the
     // enemy will be
     fire(firePower);
     execute(); // execute all commands
   }
 }