IJuniorRobotPeer MethodsRobocode Robot API for .NET
The IJuniorRobotPeer type exposes the following members.
Methods

  NameDescription
Public methodExecute
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:
Examples

SetTurnBody(90);
SetMove(100);
Execute();

while (GetDistanceRemaining() > 0 && GetTurnRemaining() > 0)
{
    Execute();
}
(Inherited from IBasicRobotPeer.)
Public methodFire
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 GetBulletDamage(Double) for getting the damage that a bullet with a specific bullet power will do.

The specified bullet power should be between MIN_BULLET_POWER and MAX_BULLET_POWER.

Note that the gun cannot Fire if the gun is overheated, meaning that GetGunHeat  returns a value > 0.

An event is generated when the bullet hits a robot (BulletHitEvent"/>, wall (BulletMissedEvent), or another bullet (BulletHitBulletEvent).

Examples

// 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.Velocity;
    }
}
(Inherited from IBasicRobotPeer.)
Public methodGetBattleFieldHeight
Returns the height of the current battlefield measured in pixels.
(Inherited from IBasicRobotPeer.)
Public methodGetBattleFieldWidth
Returns the width of the current battlefield measured in pixels.
(Inherited from IBasicRobotPeer.)
Public methodGetBodyColor
Returns current color of body
(Inherited from IBasicRobotPeer.)
Public methodGetBodyHeading
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.
(Inherited from IBasicRobotPeer.)
Public methodGetBodyTurnRemaining
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.
(Inherited from IBasicRobotPeer.)
Public methodGetBulletColor
Returns current color of bullet
(Inherited from IBasicRobotPeer.)
Public methodGetCall
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!
(Inherited from IBasicRobotPeer.)
Public methodGetDistanceRemaining
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.
(Inherited from IBasicRobotPeer.)
Public methodGetEnergy
Returns the robot's current energy.
(Inherited from IBasicRobotPeer.)
Public methodGetGraphics
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.
(Inherited from IBasicRobotPeer.)
Public methodGetGunColor
Returns current color of gun
(Inherited from IBasicRobotPeer.)
Public methodGetGunCoolingRate
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!
(Inherited from IBasicRobotPeer.)
Public methodGetGunHeading
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.
(Inherited from IBasicRobotPeer.)
Public methodGetGunHeat
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.
(Inherited from IBasicRobotPeer.)
Public methodGetGunTurnRemaining
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.
(Inherited from IBasicRobotPeer.)
Public methodGetName
Returns the robot's name.
(Inherited from IBasicRobotPeer.)
Public methodGetNumRounds
Returns the number of rounds in the current battle.
(Inherited from IBasicRobotPeer.)
Public methodGetNumSentries
Returns how many sentry robots that are left in the current round.
(Inherited from IBasicRobotPeer.)
Public methodGetOthers
Returns how many opponents that are left in the current round.
(Inherited from IBasicRobotPeer.)
Public methodGetRadarColor
Returns current color of radar
(Inherited from IBasicRobotPeer.)
Public methodGetRadarHeading
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.
(Inherited from IBasicRobotPeer.)
Public methodGetRadarTurnRemaining
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.
(Inherited from IBasicRobotPeer.)
Public methodGetRoundNum
Returns the number of the current round (0 to GetNumRounds  - 1) in the battle.
(Inherited from IBasicRobotPeer.)
Public methodGetScanColor
Returns current color of scan beam
(Inherited from IBasicRobotPeer.)
Public methodGetSentryBorderSize
Returns the sentry border size for a BorderSentry that defines the how far a BorderSentry is allowed to move from the border edges measured in units.
Hence, the sentry border size defines the width/range of the border area surrounding the battlefield that BorderSentrys cannot leave (sentry robots robots must stay in the border area), but it also define the distance from the border edges where BorderSentrys are allowed/able to make damage to robots entering this border area.
(Inherited from IBasicRobotPeer.)
Public methodGetTime
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.
(Inherited from IBasicRobotPeer.)
Public methodGetVelocity
Returns the velocity of the robot measured in pixels/turn.

The maximum velocity of a robot is defined by MAX_VELOCITY (8 pixels / turn).
(Inherited from IBasicRobotPeer.)
Public methodGetX
Returns the X position of the robot. (0,0) is at the bottom left of the battlefield.
(Inherited from IBasicRobotPeer.)
Public methodGetY
Returns the Y position of the robot. (0,0) is at the bottom left of the battlefield.
(Inherited from IBasicRobotPeer.)
Public methodMove
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.

Examples

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

// Afterwards, move the robot 50 pixels backward
Ahead(-50);
(Inherited from IBasicRobotPeer.)
Public methodRescan
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.
(Inherited from IBasicRobotPeer.)
Public methodSetBodyColor
Sets the color of the robot's body.

A null indicates the default (blue) color.

Examples

// Don't forget to using System.Drawing at the top... 
using System.Drawing;
...

public void Run()
{
    SetBodyColor(Color.BLACK);
    ...
}
The new body color
(Inherited from IBasicRobotPeer.)
Public methodSetBulletColor
Sets the color of the robot's bullets.

A null indicates the default white color.

Examples

// Don't forget to using System.Drawing at the top... 
using System.Drawing;
...

public void Run()
{
    SetBulletColor(Color.GREEN);
    ...
}
(Inherited from IBasicRobotPeer.)
Public methodSetCall
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!
(Inherited from IBasicRobotPeer.)
Public methodSetDebugProperty
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.
(Inherited from IBasicRobotPeer.)
Public methodSetFire
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 GetBulletDamage(Double) for getting the damage that a bullet with a specific bullet power will do.

The specified bullet power should be between MIN_BULLET_POWER and MAX_BULLET_POWER.

Note that the gun cannot Fire if the gun is overheated, meaning that GetGunHeat  returns a value > 0.

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

Examples

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.Velocity;
}
(Inherited from IBasicRobotPeer.)
Public methodSetGunColor
Sets the color of the robot's gun.

A null indicates the default (blue) color.

Examples

// Don't forget to using System.Drawing at the top... 
using System.Drawing;
...

public void Run()
{
    SetGunColor(Color.RED);
    ...
}
(Inherited from IBasicRobotPeer.)
Public methodSetRadarColor
Sets the color of the robot's radar.

A null indicates the default (blue) color.

Examples

// Don't forget to using System.Drawing at the top... 
using System.Drawing;
...

public void Run()
{
    SetRadarColor(Color.YELLOW);
    ...
}
(Inherited from IBasicRobotPeer.)
Public methodSetScanColor
Sets the color of the robot's scan arc.

A null indicates the default (blue) color.

Examples

// Don't forget to using System.Drawing at the top... 
using System.Drawing;
...

public void Run()
{
    SetScanColor(Color.WHITE);
    ...
}
(Inherited from IBasicRobotPeer.)
Public methodTurnAndMove
Moves this robot forward or backwards by pixels and turns this robot right or left by degrees at the same time. The robot will move in a curve that follows a perfect circle, and the moving and turning will end at exactly the same time.

Note that the max. velocity and max. turn rate is automatically adjusted, which means that the robot will move slower the sharper the turn is compared to the distance.

Note that both positive and negative values can be given as input:
  • If the distance parameter is set to a positive value, it means that the robot is set to move forward, and a negative value means that the robot is set to move backward. If set to 0, the robot will not move, but will be able to turn.
  • If the radians parameter is set to a positive value, it means that the robot is set to turn to the right, and a negative value means that the robot is set to turn to the left. If set to 0, the robot will not turn, but will be able to move.
Public methodTurnBody
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.

Examples

// 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);
(Inherited from IBasicRobotPeer.)
Public methodTurnGun
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.

Examples

// 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);
(Inherited from IBasicRobotPeer.)
Back to Top
See Also