## robocode
Class AdvancedRobot

    java.lang.Object
      robocode._Robot
          robocode.Robot
              robocode._AdvancedRobot
                  robocode._AdvancedRadiansRobot
                      robocode.AdvancedRobot

All Implemented Interfaces:
  Runnable

Direct Known Subclasses:
  TeamRobot

public class AdvancedRobot
extends _AdvancedRadiansRobot

A more advanced type of robot that allows non-blocking calls, custom events, and writes to the filesystem.

If you have not already, you should create a `Robot` first.

See Also:
  `Robot`

Field Summary

Fields inherited from class robocode.Robot
`out`

Constructor Summary
`AdvancedRobot()`

Method Summary
`void` `addCustomEvent(Condition condition)` Registers a custom event to be called when a condition is met.
`void` `clearAllEvents()` Clears out any pending events immediately.
`void` `execute()` Executes any pending actions, or continues executing actions that are in process.
`Vector` `getAllEvents()` Returns a vector containing all events currently in the robot's queue.
`Vector` `getBulletHitBulletEvents()` Returns a vector containing all BulletHitBulletEvents currently in the robot's queue.
`Vector` `getBulletHitEvents()` Returns a vector containing all BulletHitEvents currently in the robot's queue.
`Vector` `getBulletMissedEvents()` Returns a vector containing all BulletMissedEvents currently in the robot's queue.
`File` `getDataDirectory()` Returns a file representing a directory you can write to using RobocodeOutputStream.
`File` `getDataFile(String filename)` Returns a file in your data directory that you can write to RobocodeOutputStream.
`long` `getDataQuotaAvailable()` Returns the quota available in your data directory, in bytes.
`double` `getDistanceRemaining()` Gets distance left in the robot's current move.
`int` `getEventPriority(String eventClass)` Returns the current priority of a class of events.
`double` `getGunTurnRemaining()` Gets angle remaining in the gun's turn, in degrees
`Vector` `getHitByBulletEvents()` Returns a vector containing all HitByBulletEvents currently in the robot's queue.
`Vector` `getHitRobotEvents()` Returns a vector containing all HitRobotEvents currently in the robot's queue.
`Vector` `getHitWallEvents()` Returns a vector containing all HitWallEvents currently in the robot's queue.
`double` `getRadarTurnRemaining()` Gets angle remaining in the radar's turn, in degrees.
`Vector` `getRobotDeathEvents()` Returns a vector containing all RobotDeathEvents currently in the robot's queue.
`Vector` `getScannedRobotEvents()` Returns a vector containing all ScannedRobotEvents currently in the robot's queue.
`double` `getTurnRemaining()` Gets angle remaining in the robot's turn, in degrees.
`boolean` `isAdjustGunForRobotTurn()` Checks if the gun is set to adjust for the robot turning.
`boolean` `isAdjustRadarForGunTurn()` Checks if the radar is set to adjust for the gun turning.
`boolean` `isAdjustRadarForRobotTurn()` Checks if the radar is set to adjust for the robot turning.
`void` `onCustomEvent(CustomEvent event)` This method will be called when a custom condition is met See the sample robots for examples of use.
`void` `onDeath(DeathEvent event)` This method will be called if your robot dies You should override it in your robot if you want to be informed of this event.
`void` `onSkippedTurn(SkippedTurnEvent event)` This method will be called if you are taking an extremely long time between actions.
`void` `removeCustomEvent(Condition condition)` Removes a custom event (specified by condition).
`void` `setAhead(double distance)` Sets the robot to move ahead by distance This call returns immediately, and will not execute until you call execute() or take an action that executes.
`void` `setBack(double distance)` Sets the robot to move back by distance.
`void` `setEventPriority(String eventClass, int priority)` Set the priority of a class of events.
`void` `setFire(double power)` Sets the gun to fire a bullet.
`Bullet` `setFireBullet(double power)` Fires a bullet.
`void` `setInterruptible(boolean interruptible)` Call this during an event handler to allow new events of the same priority, generated following this call, to restart the event handler.
`void` `setMaxTurnRate(double newMaxTurnRate)` If you would like to turn slower than 10 degrees / tick, call this method to set it.
`void` `setMaxVelocity(double newMaxVelocity)` If you would like to limit your robot's speed to less than 8, call this method.
`void` `setResume()` Sets the robot to resume the movement you stopped in stop() or setStop(), if any.
`void` `setStop()` This call is identical to `stop()`, but returns immediately, and will not execute until you call execute() or take an action that executes.
`void` `setStop(boolean overwrite)` This call is identical to `stop(boolean)`, but returns immediately, and will not execute until you call execute() or take an action that executes.
`void` `setTurnGunLeft(double degrees)` Sets the gun to turn left by degrees This call returns immediately, and will not execute until you call execute() or take an action that executes.
`void` `setTurnGunRight(double degrees)` Sets the gun to turn right by degrees.
`void` `setTurnLeft(double degrees)` Sets the robot to turn left by degrees.
`void` `setTurnRadarLeft(double degrees)` Sets the radar to turn left by degrees.
`void` `setTurnRadarRight(double degrees)` Sets the radar to turn right by degrees.
`void` `setTurnRight(double degrees)` Sets the robot to turn right by degrees.
`void` `waitFor(Condition condition)` Does not return until condition.test() returns true.

Methods inherited from class robocode._AdvancedRadiansRobot

`getGunHeadingRadians, getGunTurnRemainingRadians, getHeadingRadians, getRadarHeadingRadians, getRadarTurnRemainingRadians, getTurnRemainingRadians, setTurnGunLeftRadians, setTurnGunRightRadians, setTurnLeftRadians, setTurnRadarLeftRadians, setTurnRadarRightRadians, setTurnRightRadians, turnGunLeftRadians, turnGunRightRadians, turnLeftRadians, turnRadarLeftRadians, turnRadarRightRadians, turnRightRadians`

Methods inherited from class robocode._AdvancedRobot
`endTurn, getGunHeadingDegrees, getHeadingDegrees, getMaxWaitCount, getRadarHeadingDegrees, getWaitCount, setTurnGunLeftDegrees, setTurnGunRightDegrees, setTurnLeftDegrees, setTurnRadarLeftDegrees, setTurnRadarRightDegrees, setTurnRightDegrees, turnGunLeftDegrees, turnGunRightDegrees, turnLeftDegrees, turnRadarLeftDegrees, turnRadarRightDegrees, turnRightDegrees`

Methods inherited from class robocode.Robot

`ahead, back, doNothing, finalize, fire, fireBullet, getBattleFieldHeight, getBattleFieldWidth, getEnergy, getGunCoolingRate, getGunHeading, getGunHeat, getHeading, getHeight, getName, getNumRounds, getOthers, getRadarHeading, getRoundNum, getTime, getVelocity, getWidth, getX, getY, onBulletHit, onBulletHitBullet, onBulletMissed, onHitByBullet, onHitRobot, onHitWall, onRobotDeath, onScannedRobot, onWin, resume, run, scan, setAdjustGunForRobotTurn, setAdjustRadarForGunTurn, setAdjustRadarForRobotTurn, setColors, stop, stop, turnGunLeft, turnGunRight, turnLeft, turnRadarLeft, turnRadarRight, turnRight`

Methods inherited from class robocode._Robot
`getBattleNum, getGunCharge, getGunImageName, getLife, getNumBattles, getRadarImageName, getRobotImageName, setGunImageName, setPeer, setRadarImageName, setRobotImageName`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### AdvancedRobot

    public AdvancedRobot()

Method Detail

### getDistanceRemaining

    public double getDistanceRemaining()

  Gets distance left in the robot's current move.

### setAhead

    public void setAhead(double distance)

  Sets the robot to move ahead by distance This call returns immediately, and will not execute until you call execute() or take an action that executes.

### setBack

    public void setBack(double distance)

  Sets the robot to move back by distance. This call returns immediately, and will not execute until you call execute() or take an action that executes.

### setTurnLeft

    public void setTurnLeft(double degrees)

  Sets the robot to turn left by degrees. This call returns immediately, and will not execute until you call execute() or take an action that executes.

### setTurnRight

    public void setTurnRight(double degrees)

  Sets the robot to turn right by degrees. This call returns immediately, and will not execute until you call execute() or take an action that executes.

### setFire

    public void setFire(double power)

  Sets the gun to fire a bullet. This call returns immediately, and will not execute until you call execute() or take an action that executes.

  Parameters:
    `power` - The energy given to the bullet, and subtracted from your energy.
  See Also:
    `Robot.fire(double)`, `Robot.fireBullet(double)`, `setFireBullet(double)`, `Robot.fireBullet(double)`

### setFireBullet

    public Bullet setFireBullet(double power)

  Fires a bullet. This call is exactly like setFire(double), but returns the Bullet object you fired. This call returns immediately, and will not execute until you call execute() or take an action that executes.

  See Also:
    `Robot.fire(double)`, `Robot.fireBullet(double)`, `setFire(double)`

### addCustomEvent

    public void addCustomEvent(Condition condition)

  Registers a custom event to be called when a condition is met. See the sample robots for examples.

  Parameters:
    `condition` - The condition that must be met.

### clearAllEvents

    public void clearAllEvents()

  Clears out any pending events immediately.

### execute

    public void execute()

  Executes any pending actions, or continues executing actions that are in process. This returns after the actions have been started. Advanced robots will probably call this function repeatedly...

  In this example the robot will move while turning

         setTurnRight(90);
         setAhead(100);
         execute();
         while (getDistanceRemaining() != 0 && getTurnRemaining() != 0) {
           execute();
         }

### getAllEvents

    public Vector getAllEvents()

  Returns a vector containing all events currently in the robot's queue. You might, for example, call this while processing another event.

  Example:

         Vector v = getAllEvents();
         Event e;
         for (int i = 0; i < v.size(); i++) {
            e = (Event)v.elementAt(i);
            if (e instanceof HitRobotEvent)
               (do something with e)
            else if (e instanceof HitByBulletEvent)
               (so something else with e)
         }

  See Also:
    `Robot.onBulletHit(robocode.BulletHitEvent)`, `Robot.onBulletHitBullet(robocode.BulletHitBulletEvent)`, `Robot.onBulletMissed(robocode.BulletMissedEvent)`, `Robot.onHitByBullet(robocode.HitByBulletEvent)`, `Robot.onHitRobot(robocode.HitRobotEvent)`, `Robot.onHitWall(robocode.HitWallEvent)`, `onSkippedTurn(robocode.SkippedTurnEvent)`, `BulletHitEvent`, `BulletMissedEvent`, `HitByBulletEvent`, `HitRobotEvent`, `HitWallEvent`, `SkippedTurnEvent`, `Event`, `Vector`

### getBulletHitBulletEvents

    public Vector getBulletHitBulletEvents()

  Returns a vector containing all BulletHitBulletEvents currently in the robot's queue. You might, for example, call this while processing another event.

  Example:

         Vector v = getBulletHitBulletEvents();
         BulletHitBulletEvent e;
         for (int i = 0; i < e.size(); i++) {
            e = (BulletHitBulletEvent)v.elementAt(i);
             (do something with e)
         }

  See Also:
    `Robot.onBulletHitBullet(robocode.BulletHitBulletEvent)`, `BulletHitBulletEvent`, `Vector`

### getBulletHitEvents

    public Vector getBulletHitEvents()

  Returns a vector containing all BulletHitEvents currently in the robot's queue. You might, for example, call this while processing another event.

  Example:

         Vector v = getBulletHitEvents();
         BulletHitEvent e;
         for (int i = 0; i < e.size(); i++) {
            e = (BulletHitEvent)v.elementAt(i);
             (do something with e)
         }

  See Also:
    `Robot.onBulletHit(robocode.BulletHitEvent)`, `BulletHitEvent`, `Vector`

### getBulletMissedEvents

    public Vector getBulletMissedEvents()

  Returns a vector containing all BulletMissedEvents currently in the robot's queue. You might, for example, call this while processing another event.

  Example:

         Vector v = getBulletHitEvents();
         BulletMissedEvent e;
         for (int i = 0; i < e.size(); i++) {
            e = (BulletMissedEvent)v.elementAt(i);
             (do something with e)
         }

  See Also:
    `Robot.onBulletMissed(robocode.BulletMissedEvent)`, `BulletMissedEvent`, `Vector`

### getDataDirectory

    public File getDataDirectory()

  Returns a file representing a directory you can write to using RobocodeOutputStream. The system will create the directory for you, you do not need to create it.

  See Also:
    `getDataFile(java.lang.String)`

### getDataFile

    public File getDataFile(String filename)

  Returns a file in your data directory that you can write to RobocodeOutputStream. The system will create the directory for you, you do not need to create it. See the sample robots for examples.

  See Also:
    `getDataDirectory()`

### getDataQuotaAvailable

    public long getDataQuotaAvailable()

  Returns the quota available in your data directory, in bytes.

  See Also:
    `getDataDirectory()`

### getEventPriority

    public int getEventPriority(String eventClass)

  Returns the current priority of a class of events. Example:

         int myHitRobotPriority = getEventPriority("HitRobotEvent");

  Parameters:
    `eventClass` - The name of the event class (string)
  See Also:
    `setEventPriority(java.lang.String, int)`

### getGunTurnRemaining

    public double getGunTurnRemaining()

  Gets angle remaining in the gun's turn, in degrees

  Returns:
    angle remaining in the gun's turn, in degrees

### getHitByBulletEvents

    public Vector getHitByBulletEvents()

  Returns a vector containing all HitByBulletEvents currently in the robot's queue. You might, for example, call this while processing another event.

  Example:

         Vector v = getHitByBulletEvents();
         HitByBulletEvent e;
         for (int i = 0; i < e.size(); i++) {
            e = (HitByBulletEvent)v.elementAt(i);
             (do something with e)
         }

  See Also:
    `Robot.onHitByBullet(robocode.HitByBulletEvent)`, `HitByBulletEvent`, `Vector`

### getHitRobotEvents

    public Vector getHitRobotEvents()

  Returns a vector containing all HitRobotEvents currently in the robot's queue. You might, for example, call this while processing another event.

  Example:

         Vector v = getHitRobotEvents();
         HitRobotEvent e;
         for (int i = 0; i < e.size(); i++) {
            e = (HitRobotEvent)v.elementAt(i);
             (do something with e)
         }

  See Also:
    `Robot.onHitRobot(robocode.HitRobotEvent)`, `HitRobotEvent`, `Vector`

### getHitWallEvents

    public Vector getHitWallEvents()

  Returns a vector containing all HitWallEvents currently in the robot's queue. You might, for example, call this while processing another event.

  Example:

         Vector v = getHitWallEvents();
         HitWallEvent e;
         for (int i = 0; i < e.size(); i++) {
            e = (HitWallEvent)v.elementAt(i);
             (do something with e)
         }

  See Also:
    `Robot.onHitWall(robocode.HitWallEvent)`, `HitWallEvent`, `Vector`

### getRadarTurnRemaining

    public double getRadarTurnRemaining()

  Gets angle remaining in the radar's turn, in degrees.

  Returns:
    angle remaining in the radar's turn

### getRobotDeathEvents

    public Vector getRobotDeathEvents()

  Returns a vector containing all RobotDeathEvents currently in the robot's queue. You might, for example, call this while processing another event.

  Example:

         Vector v = getRobotDeathEvents();
         RobotDeathEvent e;
         for (int i = 0; i < e.size(); i++) {
            e = (RobotDeathEvent)v.elementAt(i);
             (do something with e)
         }

  See Also:
    `Robot.onRobotDeath(robocode.RobotDeathEvent)`, `RobotDeathEvent`, `Vector`

### getScannedRobotEvents

    public Vector getScannedRobotEvents()

  Returns a vector containing all ScannedRobotEvents currently in the robot's queue. You might, for example, call this while processing another event.

  Example:

         Vector v = getScannedRobotEvents();
         ScannedRobotEvent e;
         for (int i = 0; i < e.size(); i++) {
            e = (ScannedRobotEvent)v.elementAt(i);
             (do something with e)
         }

  See Also:
    `Robot.onScannedRobot(robocode.ScannedRobotEvent)`, `ScannedRobotEvent`, `Vector`

### getTurnRemaining

    public double getTurnRemaining()

  Gets angle remaining in the robot's turn, in degrees.

  Returns:
    angle remaining in the robot's turn, in degrees

### isAdjustGunForRobotTurn

    public boolean isAdjustGunForRobotTurn()

  Checks if the gun is set to adjust for the robot turning.

  Returns:
    if the gun is set to adjust for the robot turning.
  See Also:
    `Robot.setAdjustGunForRobotTurn(boolean)`

### isAdjustRadarForGunTurn

    public boolean isAdjustRadarForGunTurn()

  Checks if the radar is set to adjust for the gun turning.

  Returns:
    if the radar is set to adjust for the gun turning.
  See Also:
    `Robot.setAdjustRadarForGunTurn(boolean)`

### onCustomEvent

    public void onCustomEvent(CustomEvent event)

  This method will be called when a custom condition is met See the sample robots for examples of use.

  Parameters:
    `event` - The event set by the game
  See Also:
    `addCustomEvent(robocode.Condition)`, `CustomEvent`, `Event`

### removeCustomEvent

    public void removeCustomEvent(Condition condition)

  Removes a custom event (specified by condition). See the sample robots for examples of use.

  Parameters:
    `condition` - The condition to remove
  See Also:
    `addCustomEvent(robocode.Condition)`

### setEventPriority

    public void setEventPriority(String eventClass,
                                 int priority)

  Set the priority of a class of events. Events are sent to the onXxxxxx handlers in order of priority, and higher priority events can interrupt lower priority events. For events with the same priority, newer events are always sent first. Valid priorities are 0-99. 100 is reserved. Example:

        setEventPriority("RobotDeathEvent",15);

  The default priorities are, from lowest to highest:

      	ScannedRobotEvent: 		10
      	HitRobotEvent:     		20
      	HitWallEvent:      		30
      	HitByBulletEvent:  		40
      	BulletHitEvent:    		50
      	BulletHitBulletEvent:	50
      	BulletMissedEvent: 		60
      	RobotDeathEvent:   		70
      	CustomEvent:       		80
      	SkippedTurnEvent:  		100
      	WinEvent:          		100
      	DeathEvent:        		100

  Parameters:
    `eventClass` - String containing name of the event class you wish to set priority for
    `priority` - the new priority for that class
  See Also:
    `_Robot.setInterruptible(boolean)`

### setInterruptible

    public void setInterruptible(boolean interruptible)

  Call this during an event handler to allow new events of the same priority, generated following this call, to restart the event handler.

  Example

         onScannedRobot(ScannedRobotEvent e) {
             fire(1);
             setInterruptible(true);
             ahead(100); // If you see a robot while moving ahead,
                         // this handler will start from the top
                         // Without setInterruptible, we wouldn't
                         // receive scan events at all!
             // We'll only get here if we don't see a robot during the move.
             out.println("Ok, I can't see anyone");
         }

  Overrides:
    `setInterruptible` in class `_Robot`
  Parameters:
    `interruptible` - Whether this event handler should be interrupted on new events of same priority.

### setMaxTurnRate

    public void setMaxTurnRate(double newMaxTurnRate)

  If you would like to turn slower than 10 degrees / tick, call this method to set it.

### setMaxVelocity

    public void setMaxVelocity(double newMaxVelocity)

  If you would like to limit your robot's speed to less than 8, call this method.

### setResume

    public void setResume()

  Sets the robot to resume the movement you stopped in stop() or setStop(), if any. This call returns immediately, and will not execute until you call execute() or take an action that executes.

  See Also:
    `setStop()`, `Robot.stop()`

### setStop

    public void setStop()

  This call is identical to `stop()`, but returns immediately, and will not execute until you call execute() or take an action that executes. If there is already movement saved from a previous stop, this will have no effect. This call is equivalent to calling setStop(false);

  See Also:
    `setStop(boolean)`, `setResume()`, `Robot.stop()`, `Robot.resume()`

### setStop

    public void setStop(boolean overwrite)

  This call is identical to `stop(boolean)`, but returns immediately, and will not execute until you call execute() or take an action that executes. If there is already movement saved from a previous stop, you can overwrite it by calling setStop(true).

  See Also:
    `setStop()`, `setResume()`, `Robot.stop()`, `Robot.resume()`

### setTurnGunLeft

    public void setTurnGunLeft(double degrees)

  Sets the gun to turn left by degrees This call returns immediately, and will not execute until you call execute() or take an action that executes.

### setTurnGunRight

    public void setTurnGunRight(double degrees)

  Sets the gun to turn right by degrees. This call returns immediately, and will not execute until you call execute() or take an action that executes.

### setTurnRadarLeft

    public void setTurnRadarLeft(double degrees)

  Sets the radar to turn left by degrees. This call returns immediately, and will not execute until you call execute() or take an action that executes.

### setTurnRadarRight

    public void setTurnRadarRight(double degrees)

  Sets the radar to turn right by degrees. This call returns immediately, and will not execute until you call execute() or take an action that executes.

### waitFor

    public void waitFor(Condition condition)

  Does not return until condition.test() returns true. This call executes immediately. See the example robots for usage.

### isAdjustRadarForRobotTurn

    public boolean isAdjustRadarForRobotTurn()

  Checks if the radar is set to adjust for the robot turning.

  Returns:
    if the radar is set to adjust for the robot turning.
  See Also:
    `Robot.setAdjustRadarForRobotTurn(boolean)`

### onDeath

    public void onDeath(DeathEvent event)

  This method will be called if your robot dies You should override it in your robot if you want to be informed of this event. Actions will have no effect if called from this section. The intent is to allow you to perform calculations or print something out when you lose.

  Overrides:
    `onDeath` in class `Robot`
  Parameters:
    `event` - The event set by the game
  See Also:
    `DeathEvent`, `Event`

### onSkippedTurn

    public void onSkippedTurn(SkippedTurnEvent event)

  This method will be called if you are taking an extremely long time between actions. If you receive 30 of these, your robot will be removed from the round. You will only receive this event after taking an action... so a robot in an infinite loop will not receive any events, and will simply be stopped. No correctly working, reasonable robot should ever receive this event.

  Parameters:
    `event` - The event set by the game
  See Also:
    `SkippedTurnEvent`, `Event`