## robocode.robotinterfaces.peer
Interface IBasicRobotPeer

All Known Subinterfaces:
  IAdvancedRobotPeer, IJuniorRobotPeer, IStandardRobotPeer, ITeamRobotPeer

    public interface IBasicRobotPeer

The basic robot peer for all robot types.

NOTE: This is private interface. You should build any external component (or robot) based on it's current methods because it will change in the future.

A robot peer is the object that deals with game mechanics and rules, and makes sure your robot abides by them.

Since:
  1.6
Author:
  Pavel Savara (original), Flemming N. Larsen (contributor)
See Also:
  `IStandardRobotPeer`, `IAdvancedRobotPeer`, `ITeamRobotPeer`, `IJuniorRobotPeer`

Method Summary
`void` `execute()` Executes any pending actions, or continues executing actions that are in process.
`Bullet` `fire(double power)` Immediately fires a bullet.
`double` `getBattleFieldHeight()` Returns the height of the current battlefield measured in pixels.
`double` `getBattleFieldWidth()` Returns the width of the current battlefield measured in pixels.
`double` `getBodyHeading()` Returns the direction that the robot's body is facing, in radians.
`double` `getBodyTurnRemaining()` Returns the angle remaining in the robot's turn, in radians.
`void` `getCall()` This call must be made from a robot call to inform the game that the robot made a `get*` call like e.g.
`double` `getDistanceRemaining()` Returns the distance remaining in the robot's current move measured in pixels.
`double` `getEnergy()` Returns the robot's current energy.
`Graphics2D` `getGraphics()` Returns a graphics context used for painting graphical items for the robot.
`double` `getGunCoolingRate()` Returns the rate at which the gun will cool down, i.e. the amount of heat the gun heat will drop per turn.
`double` `getGunHeading()` Returns the direction that the robot's gun is facing, in radians.
`double` `getGunHeat()` Returns the current heat of the gun.
`double` `getGunTurnRemaining()` Returns the angle remaining in the gun's turn, in radians.
`String` `getName()` Returns the robot's name.
`int` `getNumRounds()` Returns the number of rounds in the current battle.
`int` `getOthers()` Returns how many opponents that are left in the current round.
`double` `getRadarHeading()` Returns the direction that the robot's radar is facing, in radians.
`double` `getRadarTurnRemaining()` Returns the angle remaining in the radar's turn, in radians.
`int` `getRoundNum()` Returns the number of the current round (0 to `getNumRounds()` - 1) in the battle.
`long` `getTime()` Returns the game time of the current round, where the time is equal to the current turn in the round.
`double` `getVelocity()` Returns the velocity of the robot measured in pixels/turn.
`double` `getX()` Returns the X position of the robot. (0,0) is at the bottom left of the battlefield.
`double` `getY()` Returns the Y position of the robot. (0,0) is at the bottom left of the battlefield.
`void` `move(double distance)` Immediately moves your robot forward or backward by distance measured in pixels.
`void` `rescan()` Rescan for other robots.
`void` `setBodyColor(Color color)` Sets the color of the robot's body.
`void` `setBulletColor(Color color)` Sets the color of the robot's bullets.
`void` `setCall()` This call must be made from a robot call to inform the game that the robot made a `set*` call like e.g.
`void` `setDebugProperty(String key, String value)` Sets the debug property with the specified key to the specified value.
`Bullet` `setFire(double power)` Sets the gun to fire a bullet when the next execution takes place.
`void` `setGunColor(Color color)` Sets the color of the robot's gun.
`void` `setRadarColor(Color color)` Sets the color of the robot's radar.
`void` `setScanColor(Color color)` Sets the color of the robot's scan arc.
`void` `turnBody(double radians)` Immediately turns the robot's body to the right or left by radians.
`void` `turnGun(double radians)` Immediately turns the robot's gun to the right or left by radians.

Method Detail

### getName

    String getName()

  Returns the robot's name.

  Returns:
    the robot's name.

### getTime

    long getTime()

  Returns the game time of the current round, where the time is equal to the current turn in the round.

  A battle consists of multiple rounds.

  Time is reset to 0 at the beginning of every round.

  Returns:
    the game time/turn of the current round.

### getEnergy

    double getEnergy()

  Returns the robot's current energy.

  Returns:
    the robot's current energy.

### getX

    double getX()

  Returns the X position of the robot. (0,0) is at the bottom left of the battlefield.

  Returns:
    the X position of the robot.
  See Also:
    `getY()`

### getY

    double getY()

  Returns the Y position of the robot. (0,0) is at the bottom left of the battlefield.

  Returns:
    the Y position of the robot.
  See Also:
    `getX()`

### getVelocity

    double getVelocity()

  Returns the velocity of the robot measured in pixels/turn.

  The maximum velocity of a robot is defined by `Rules.MAX_VELOCITY` (8 pixels / turn).

  Returns:
    the velocity of the robot measured in pixels/turn.
  See Also:
    `Rules.MAX_VELOCITY`

### getBodyHeading

    double getBodyHeading()

  Returns the direction that the robot's body is facing, in radians. The value returned will be between 0 and 2 * PI (is excluded).

  Note that the heading in Robocode is like a compass, where 0 means North, PI / 2 means East, PI means South, and 3 * PI / 2 means West.

  Returns:
    the direction that the robot's body is facing, in radians.
  See Also:
    `getGunHeading()`, `getRadarHeading()`

### getGunHeading

    double getGunHeading()

  Returns the direction that the robot's gun is facing, in radians. The value returned will be between 0 and 2 * PI (is excluded).

  Note that the heading in Robocode is like a compass, where 0 means North, PI / 2 means East, PI means South, and 3 * PI / 2 means West.

  Returns:
    the direction that the robot's gun is facing, in radians.
  See Also:
    `getBodyHeading()`, `getRadarHeading()`

### getRadarHeading

    double getRadarHeading()

  Returns the direction that the robot's radar is facing, in radians. The value returned will be between 0 and 2 * PI (is excluded).

  Note that the heading in Robocode is like a compass, where 0 means North, PI / 2 means East, PI means South, and 3 * PI / 2 means West.

  Returns:
    the direction that the robot's radar is facing, in radians.
  See Also:
    `getBodyHeading()`, `getGunHeading()`

### getGunHeat

    double getGunHeat()

  Returns the current heat of the gun. The gun cannot fire unless this is 0. (Calls to fire will succeed, but will not actually fire unless getGunHeat() == 0).

  The amount of gun heat generated when the gun is fired is 1 + (firePower / 5). Each turn the gun heat drops by the amount returned by `getGunCoolingRate()`, which is a battle setup.

  Note that all guns are "hot" at the start of each round, where the gun heat is 3.

  Returns:
    the current gun heat
  See Also:
    `getGunCoolingRate()`, `setFire(double)`

### getBattleFieldWidth

    double getBattleFieldWidth()

  Returns the width of the current battlefield measured in pixels.

  Returns:
    the width of the current battlefield measured in pixels.

### getBattleFieldHeight

    double getBattleFieldHeight()

  Returns the height of the current battlefield measured in pixels.

  Returns:
    the height of the current battlefield measured in pixels.

### getOthers

    int getOthers()

  Returns how many opponents that are left in the current round.

  Returns:
    how many opponents that are left in the current round.

### getNumRounds

    int getNumRounds()

  Returns the number of rounds in the current battle.

  Returns:
    the number of rounds in the current battle.
  See Also:
    `getRoundNum()`

### getRoundNum

    int getRoundNum()

  Returns the number of the current round (0 to `getNumRounds()` - 1) in the battle.

  Returns:
    the number of the current round in the battle (zero indexed).
  See Also:
    `getNumRounds()`

### getGunCoolingRate

    double getGunCoolingRate()

  Returns the rate at which the gun will cool down, i.e. the amount of heat the gun heat will drop per turn.

  The gun cooling rate is default 0.1 / turn, but can be changed by the battle setup. So don't count on the cooling rate being 0.1!

  Returns:
    the gun cooling rate
  See Also:
    `getGunHeat()`, `setFire(double)`

### getDistanceRemaining

    double getDistanceRemaining()

  Returns the distance remaining in the robot's current move measured in pixels.

  This call returns both positive and negative values. Positive values means that the robot is currently moving forwards. Negative values means that the robot is currently moving backwards. If the returned value is 0, the robot currently stands still.

  Returns:
    the distance remaining in the robot's current move measured in pixels.
  See Also:
    `getBodyTurnRemaining()`, `getGunTurnRemaining()`, `getRadarTurnRemaining()`

### getBodyTurnRemaining

    double getBodyTurnRemaining()

  Returns the angle remaining in the robot's turn, in radians.

  This call returns both positive and negative values. Positive values means that the robot is currently turning to the right. Negative values means that the robot is currently turning to the left.

  Returns:
    the angle remaining in the robot's turn, in radians
  See Also:
    `getDistanceRemaining()`, `getGunTurnRemaining()`, `getRadarTurnRemaining()`

### getGunTurnRemaining

    double getGunTurnRemaining()

  Returns the angle remaining in the gun's turn, in radians.

  This call returns both positive and negative values. Positive values means that the gun is currently turning to the right. Negative values means that the gun is currently turning to the left.

  Returns:
    the angle remaining in the gun's turn, in radians
  See Also:
    `getDistanceRemaining()`, `getBodyTurnRemaining()`, `getRadarTurnRemaining()`

### getRadarTurnRemaining

    double getRadarTurnRemaining()

  Returns the angle remaining in the radar's turn, in radians.

  This call returns both positive and negative values. Positive values means that the radar is currently turning to the right. Negative values means that the radar is currently turning to the left.

  Returns:
    the angle remaining in the radar's turn, in radians
  See Also:
    `getDistanceRemaining()`, `getBodyTurnRemaining()`, `getGunTurnRemaining()`

### execute

    void execute()

  Executes any pending actions, or continues executing actions that are in process. This call returns after the actions have been started.

  Note that advanced robots must call this function in order to execute pending set* calls like e.g. `setMove(double)`, `setFire(double)`, `setTurnBody(double)` etc. Otherwise, these calls will never get executed.

  In this example the robot will move while turning:

         setTurnBody(90);
         setMove(100);
         execute();

         while (getDistanceRemaining() > 0 && getTurnRemaining() > 0) {
             execute();
         }

### move

    void move(double distance)

  Immediately moves your robot forward or backward by distance measured in pixels.

  This call executes immediately, and does not return until it is complete, i.e. when the remaining distance to move is 0.

  If the robot collides with a wall, the move is complete, meaning that the robot will not move any further. If the robot collides with another robot, the move is complete if you are heading toward the other robot.

  Note that both positive and negative values can be given as input, where positive values means that the robot is set to move forward, and negative values means that the robot is set to move backward.

  Example:

         // Move the robot 100 pixels forward
         ahead(100);

         // Afterwards, move the robot 50 pixels backward
         ahead(-50);

  Parameters:
    `distance` - the distance to move measured in pixels. If `distance` > 0 the robot is set to move forward. If `distance` < 0 the robot is set to move backward. If `distance` = 0 the robot will not move anywhere, but just finish its turn.
  See Also:
    `IBasicEvents.onHitWall(robocode.HitWallEvent)`, `IBasicEvents.onHitRobot(robocode.HitRobotEvent)`

### turnBody

    void turnBody(double radians)

  Immediately turns the robot's body to the right or left by radians. This call executes immediately, and does not return until it is complete, i.e. when the angle remaining in the body's turn is 0.

  Note that both positive and negative values can be given as input, where positive values means that the robot's body is set to turn right, and negative values means that the robot's body is set to turn left. If 0 is given as input, the robot's body will stop turning.

  Example:

         // Turn the robot's body 180 degrees to the right
         turnBody(Math.PI);

         // Afterwards, turn the robot's body 90 degrees to the left
         turnBody(-Math.PI / 2);

  Parameters:
    `radians` - the amount of radians to turn the robot's body. If `radians` > 0 the robot's body is set to turn right. If `radians` < 0 the robot's body is set to turn left. If `radians` = 0 the robot's body is set to stop turning.
  See Also:
    `turnGun(double)`, `turnRadar(double)`, `move(double)`

### turnGun

    void turnGun(double radians)

  Immediately turns the robot's gun to the right or left by radians. This call executes immediately, and does not return until it is complete, i.e. when the angle remaining in the gun's turn is 0.

  Note that both positive and negative values can be given as input, where positive values means that the robot's gun is set to turn right, and negative values means that the robot's gun is set to turn left. If 0 is given as input, the robot's gun will stop turning.

  Example:

         // Turn the robot's gun 180 degrees to the right
         turnGun(Math.PI);

         // Afterwards, turn the robot's gun 90 degrees to the left
         turnGun(-Math.PI / 2);

  Parameters:
    `radians` - the amount of radians to turn the robot's gun. If `radians` > 0 the robot's gun is set to turn right. If `radians` < 0 the robot's gun is set to turn left. If `radians` = 0 the robot's gun is set to stop turning.
  See Also:
    `turnBody(double)`, `turnRadar(double)`, `move(double)`

### fire

    Bullet fire(double power)

  Immediately fires a bullet. The bullet will travel in the direction the gun is pointing.

  The specified bullet power is an amount of energy that will be taken from the robot's energy. Hence, the more power you want to spend on the bullet, the more energy is taken from your robot.

  The bullet will do (4 * power) damage if it hits another robot. If power is greater than 1, it will do an additional 2 * (power - 1) damage. You will get (3 * power) back if you hit the other robot. You can call `Rules.getBulletDamage(double)` for getting the damage that a bullet with a specific bullet power will do.

  The specified bullet power should be between `Rules.MIN_BULLET_POWER` and `Rules.MAX_BULLET_POWER`.

  Note that the gun cannot fire if the gun is overheated, meaning that `getGunHeat()` returns a value > 0.

  A event is generated when the bullet hits a robot (`BulletHitEvent`), wall (`BulletMissedEvent`), or another bullet (`BulletHitBulletEvent`).

  Example:

         // Fire a bullet with maximum power if the gun is ready
         if (getGunHeat() == 0) {
             Bullet bullet = fire(Rules.MAX_BULLET_POWER);

             // Get the velocity of the bullet
             if (bullet != null) {
                 double bulletVelocity = bullet.getVelocity();
             }
         }

  Parameters:
    `power` - the amount of energy given to the bullet, and subtracted from the robot's energy.
  Returns:
    a `Bullet` that contains information about the bullet if it was actually fired, which can be used for tracking the bullet after it has been fired. If the bullet was not fired, `null` is returned.
  See Also:
    `setFire(double)`, `Bullet`, `getGunHeat()`, `getGunCoolingRate()`, `onBulletHit(BulletHitEvent)`, `onBulletHitBullet(BulletHitBulletEvent)`, `onBulletMissed(BulletMissedEvent)`

### setFire

    Bullet setFire(double power)

  Sets the gun to fire a bullet when the next execution takes place. The bullet will travel in the direction the gun is pointing.

  This call returns immediately, and will not execute until you call execute() or take an action that executes.

  The specified bullet power is an amount of energy that will be taken from the robot's energy. Hence, the more power you want to spend on the bullet, the more energy is taken from your robot.

  The bullet will do (4 * power) damage if it hits another robot. If power is greater than 1, it will do an additional 2 * (power - 1) damage. You will get (3 * power) back if you hit the other robot. You can call `Rules.getBulletDamage(double)` for getting the damage that a bullet with a specific bullet power will do.

  The specified bullet power should be between `Rules.MIN_BULLET_POWER` and `Rules.MAX_BULLET_POWER`.

  Note that the gun cannot fire if the gun is overheated, meaning that `getGunHeat()` returns a value > 0.

  A event is generated when the bullet hits a robot (`BulletHitEvent`), wall (`BulletMissedEvent`), or another bullet (`BulletHitBulletEvent`).

  Example:

         Bullet bullet = null;

         // Fire a bullet with maximum power if the gun is ready
         if (getGunHeat() == 0) {
             bullet = setFireBullet(Rules.MAX_BULLET_POWER);
         }
         ...
         execute();
         ...
         // Get the velocity of the bullet
         if (bullet != null) {
             double bulletVelocity = bullet.getVelocity();
         }

  Parameters:
    `power` - the amount of energy given to the bullet, and subtracted from the robot's energy.
  Returns:
    a `Bullet` that contains information about the bullet if it was actually fired, which can be used for tracking the bullet after it has been fired. If the bullet was not fired, `null` is returned.
  See Also:
    `fire(double)`, `Bullet`, `getGunHeat()`, `getGunCoolingRate()`, `onBulletHit(BulletHitEvent)`, `onBulletHitBullet(BulletHitBulletEvent)`, `onBulletMissed(BulletMissedEvent)`

### setBodyColor

    void setBodyColor(Color color)

  Sets the color of the robot's body.

  A `null` indicates the default (blue) color.

       Example:
         // Don't forget to import java.awt.Color at the top...
         import java.awt.Color;
         ...

         public void run() {
             setBodyColor(Color.BLACK);
             ...
         }

  Parameters:
    `color` - the new body color
  Since:
    1.1.2
  See Also:
    `setGunColor(Color)`, `setRadarColor(Color)`, `setBulletColor(Color)`, `setScanColor(Color)`, `Color`

### setGunColor

    void setGunColor(Color color)

  Sets the color of the robot's gun.

  A `null` indicates the default (blue) color.

       Example:
         // Don't forget to import java.awt.Color at the top...
         import java.awt.Color;
         ...

         public void run() {
             setGunColor(Color.RED);
             ...
         }

  Parameters:
    `color` - the new gun color
  Since:
    1.1.2
  See Also:
    `setBodyColor(Color)`, `setRadarColor(Color)`, `setBulletColor(Color)`, `setScanColor(Color)`, `Color`

### setRadarColor

    void setRadarColor(Color color)

  Sets the color of the robot's radar.

  A `null` indicates the default (blue) color.

       Example:
         // Don't forget to import java.awt.Color at the top...
         import java.awt.Color;
         ...

         public void run() {
             setRadarColor(Color.YELLOW);
             ...
         }

  Parameters:
    `color` - the new radar color
  Since:
    1.1.2
  See Also:
    `setBodyColor(Color)`, `setGunColor(Color)`, `setBulletColor(Color)`, `setScanColor(Color)`, `Color`

### setBulletColor

    void setBulletColor(Color color)

  Sets the color of the robot's bullets.

  A `null` indicates the default white color.

       Example:
         // Don't forget to import java.awt.Color at the top...
         import java.awt.Color;
         ...

         public void run() {
             setBulletColor(Color.GREEN);
             ...
         }

  Parameters:
    `color` - the new bullet color
  Since:
    1.1.2
  See Also:
    `setBodyColor(Color)`, `setGunColor(Color)`, `setRadarColor(Color)`, `setScanColor(Color)`, `Color`

### setScanColor

    void setScanColor(Color color)

  Sets the color of the robot's scan arc.

  A `null` indicates the default (blue) color.

       Example:
         // Don't forget to import java.awt.Color at the top...
         import java.awt.Color;
         ...

         public void run() {
             setScanColor(Color.WHITE);
             ...
         }

  Parameters:
    `color` - the new scan arc color
  Since:
    1.1.2
  See Also:
    `setBodyColor(Color)`, `setGunColor(Color)`, `setRadarColor(Color)`, `setBulletColor(Color)`, `Color`

### getCall

    void getCall()

  This call must be made from a robot call to inform the game that the robot made a `get*` call like e.g. `getX()` or `getVelocity()`.

  This method is used by the game to determine if the robot is inactive or not. Note: You should only make this call once in a `get*` method!

  See Also:
    `setCall()`

### setCall

    void setCall()

  This call must be made from a robot call to inform the game that the robot made a `set*` call like e.g. `setFire(double)` or `setBodyColor(Color)`.

  This method is used by the game to determine if the robot is inactive or not. Note: You should only make this call once in a `set*` method!

  See Also:
    `getCall()`

### getGraphics

    Graphics2D getGraphics()

  Returns a graphics context used for painting graphical items for the robot.

  This method is very useful for debugging your robot.

  Note that the robot will only be painted if the "Paint" is enabled on the robot's console window; otherwise the robot will never get painted (the reason being that all robots might have graphical items that must be painted, and then you might not be able to tell what graphical items that have been painted for your robot).

  Also note that the coordinate system for the graphical context where you paint items fits for the Robocode coordinate system where (0, 0) is at the bottom left corner of the battlefield, where X is towards right and Y is upwards.

  Returns:
    a graphics context used for painting graphical items for the robot.
  Since:
    1.6.1
  See Also:
    `IPaintEvents.onPaint(Graphics2D)`

### setDebugProperty

    void setDebugProperty(String key,
                          String value)

  Sets the debug property with the specified key to the specified value.

  This method is very useful when debugging or reviewing your robot as you will be able to see this property displayed in the robot console for your robots under the Debug Properties tab page.

  Parameters:
    `key` - the name/key of the debug property.
    `value` - the new value of the debug property, where `null` or the empty string is used for removing this debug property.
  Since:
    1.6.2

### rescan

    void rescan()

  Rescan for other robots. This method is called automatically by the game, as long as the robot is moving, turning its body, turning its gun, or turning its radar.

  Rescan will cause `onScannedRobot(ScannedRobotEvent)` to be called if you see a robot.

  There are 2 reasons to call `rescan()` manually:
  1. You want to scan after you stop moving.
  2. You want to interrupt the `onScannedRobot` event. This is more likely. If you are in `onScannedRobot` and call `scan()`, and you still see a robot, then the system will interrupt your `onScannedRobot` event immediately and start it from the top.

  This call executes immediately.

  Since:
    1.7.2
  See Also:
    `onScannedRobot(ScannedRobotEvent)`, `ScannedRobotEvent`

Copyright © 2013 Robocode. All Rights Reserved.