CenterBot template


import robocode.*;
// API help : http://robocode.sourceforge.net/docs/robocode/robocode/Robot.html

// Approach #1: Get robot's current heading. Turn robot to point north (heading=0).
// Move robot ahead or back to get to middle of screen vertically. Turn robot to
// point east (heading=90). Move robot ahead or back to get to middle of screen
// horizontally.

/**
 * CenterBot - a robot by (your name here)
 */
public class CenterBot extends Robot
{
   // Declare some robot variables here:
   private double centerX;
   private double centerY;


      
   /**
    * run: CenterBot's default behavior
    */
   public void run() {
      // Compute x and y for center of field:
      // (Note: It's illegal to call getBattleFieldHeight() and getBattleFieldWidth()
      //        before the run() method, so must call those methods in here.)
      centerX = getBattleFieldWidth() / 2;  
      centerY = getBattleFieldHeight() / 2;

      
      
      // Robot main loop
      while(true) {
         // Get current heading:
         double currentHeading = getHeading();
         
         // Point myself north:
         turnRight( 360 - currentHeading );

         // Move ahead or back to get to center, vertically:
         // (If your y coordinate is > centerY, move back so your y = centerY.)
         // (If your y coordinate is < centerY, move ahead so your y = centerY.)         

         
         // Turn east:

         
         // Move ahead or back to get to center, horizontally:
         // (If your x coordinate is > centerX, move back so your x = centerX.)
         // (If your x coordinate is < centerX, move ahead so your x = centerX.)         


         // Spin in a circle (turn in place) and stop:
      
      
      }


   }
   

}