AdvancedRobot (Robocode 1.2.4-Beta API)

Overview | Package | Class | Tree | Deprecated | Index | Help

PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## robocode
Class AdvancedRobot

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

All Implemented Interfaces:
  java.lang.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.

Author:
  Mathew A. Nelson (original), Flemming N. Larsen (contributor), Robert D. Maupin (contributor)
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.
`java.util.Vector<Event>` | `getAllEvents()` Returns a vector containing all events currently in the robot's queue.
`java.util.Vector<BulletHitBulletEvent>` | `getBulletHitBulletEvents()` Returns a vector containing all BulletHitBulletEvents currently in the robot's queue.
`java.util.Vector<BulletHitEvent>` | `getBulletHitEvents()` Returns a vector containing all BulletHitEvents currently in the robot's queue.
`java.util.Vector<BulletMissedEvent>` | `getBulletMissedEvents()` Returns a vector containing all BulletMissedEvents currently in the robot's queue.
`java.io.File` | `getDataDirectory()` Returns a file representing a directory you can write to using RobocodeOutputStream.
`java.io.File` | `getDataFile(java.lang.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(java.lang.String eventClass)` Returns the current priority of a class of events.
`double` | `getGunTurnRemaining()` Gets angle remaining in the gun's turn, in degrees
`java.util.Vector<HitByBulletEvent>` | `getHitByBulletEvents()` Returns a vector containing all HitByBulletEvents currently in the robot's queue.
`java.util.Vector<HitRobotEvent>` | `getHitRobotEvents()` Returns a vector containing all HitRobotEvents currently in the robot's queue.
`java.util.Vector<HitWallEvent>` | `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.
`java.util.Vector<RobotDeathEvent>` | `getRobotDeathEvents()` Returns a vector containing all RobotDeathEvents currently in the robot's queue.
`java.util.Vector<ScannedRobotEvent>` | `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(java.lang.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, onPaint, onRobotDeath, onScannedRobot, onWin, resume, run, scan, setAdjustGunForRobotTurn, setAdjustRadarForGunTurn, setAdjustRadarForRobotTurn, setAllColors, setBodyColor, setBulletColor, setColors, setColors, setGunColor, setRadarColor, setScanColor, 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, uninitializedException`

Methods inherited from class java.lang.Object
`clone, 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 or null if the bullet was not 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 java.util.Vector<Event> getAllEvents()

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

  Example:

         for (Event e : getAllEvents()) {
            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 java.util.Vector<BulletHitBulletEvent> getBulletHitBulletEvents()

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

  Example:

         for (BulletHitBulletEvent e : getBulletHitBulletEvents()) {
             (do something with e)
         }

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

### getBulletHitEvents

    public java.util.Vector<BulletHitEvent> getBulletHitEvents()

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

  Example:

         for (BulletHitEvent : getBulletHitEvents()) {
             (do something with e)
         }

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

### getBulletMissedEvents

    public java.util.Vector<BulletMissedEvent> getBulletMissedEvents()

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

  Example:

         for (BulletMissedEvent e : getBulletHitEvents()) {
             (do something with e)
         }

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

### getDataDirectory

    public java.io.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 java.io.File getDataFile(java.lang.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(java.lang.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 java.util.Vector<HitByBulletEvent> getHitByBulletEvents()

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

  Example:

         for (HitByBulletEvent e : getHitByBulletEvents()) {
             (do something with e)
         }

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

### getHitRobotEvents

    public java.util.Vector<HitRobotEvent> getHitRobotEvents()

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

  Example:

         for (HitRobotEvent e : getHitRobotEvents()) {
             (do something with e)
         }

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

### getHitWallEvents

    public java.util.Vector<HitWallEvent> getHitWallEvents()

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

  Example:

         for (HitWallEvent e : getHitWallEvents()) {
             (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 java.util.Vector<RobotDeathEvent> getRobotDeathEvents()

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

  Example:

         for (RobotDeathEvent e : getRobotDeathEvents()) {
             (do something with e)
         }

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

### getScannedRobotEvents

    public java.util.Vector<ScannedRobotEvent> getScannedRobotEvents()

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

  Example:

         for (ScannedRobotEvent e : getScannedRobotEvents()) {
             (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(java.lang.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`

Overview | Package | Class | Tree | Deprecated | Index | Help

PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD