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

  NameDescription
Public methodAddCustomEvent
Registers a custom event to be called when a condition is met. When you are finished with your condition or just want to remove it you must call RemoveCustomEvent(Condition).

Examples

AddCustomEvent(
    new Condition("triggerhit", (c) =>
    {
       return Energy <= trigger;
    }));

// Add our custom event based on our condition
AddCustomEvent(triggerHitCondition);
(Inherited from IAdvancedRobotPeer.)
Public methodBroadcastMessage
Broadcasts a message to all teammates.

Examples

public void Run()
{
    BroadcastMessage("I'm here!");
}
Public methodclearAllEvents
Clears Out any pending events in the robot's event queue immediately.
(Inherited from IAdvancedRobotPeer.)
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 methodGetAllEvents
Returns a list containing all events currently in the robot's queue. You might, for example, call this while processing another event.

Examples

foreach (Event evnt in GetAllEvents())
{
    if (event is HitRobotEvent)
    {
        // do something with the event
    }
    else if (event is HitByBulletEvent)
    {
        // do something with the event
    }
}
(Inherited from IAdvancedRobotPeer.)
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 methodGetBulletHitBulletEvents
Returns a list containing all BulletHitBulletEvents currently in the robot's queue. You might, for example, call this while processing another event.

Examples

foreach (BulletHitBulletEvent evnt inGetBulletHitBulletEvents())
{
    // do something with the event
}
(Inherited from IAdvancedRobotPeer.)
Public methodGetBulletHitEvents
Returns a list containing all BulletHitEvents currently in the robot's queue. You might, for example, call this while processing another event.

Examples

foreach (BulletHitEvent event: GetBulletHitEvents())
{
    // do something with the event
}
(Inherited from IAdvancedRobotPeer.)
Public methodGetBulletMissedEvents
Returns a list containing all BulletMissedEvents currently in the robot's queue. You might, for example, call this while processing another event.

Examples

foreach (BulletMissedEvent evnt inGetBulletMissedEvents())
{
    // do something with the event
}
(Inherited from IAdvancedRobotPeer.)
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 methodGetDataDirectory
Returns a file representing a data directory for the robot, which can be written to.

The system will automatically create the directory for you, so you do not need to create it by yourself.
(Inherited from IAdvancedRobotPeer.)
Public methodGetDataFile
Returns a file in your data directory that you can write to.

The system will automatically create the directory for you, so you do not need to create it by yourself.

Please notice that the max. size of your data file is set to 200000 (~195 KB).

See the Sample.SittingDuck to see an example of how to use this method.
(Inherited from IAdvancedRobotPeer.)
Public methodGetDataQuotaAvailable
Returns the data quota available in your data directory, i.e. the amount of bytes left in the data directory for the robot.
(Inherited from IAdvancedRobotPeer.)
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 methodGetEventPriority
Returns the current priority of a class of events. An event priority is a value from 0 - 99. The higher value, the higher priority.

Examples

int myHitRobotPriority = GetEventPriority("HitRobotEvent");

The default priorities are, from highest to lowest:
<see cref="T:Robocode.BattleEndedEvent" />:     100 (reserved)
              <see cref="T:Robocode.WinEvent" />:             100 (reserved)
              <see cref="T:Robocode.SkippedTurnEvent" />:     100 (reserved)
              <see cref="T:Robocode.StatusEvent" />:           99
              Key and mouse events:  98
              <see cref="T:Robocode.CustomEvent" />:           80 (default value)
              <see cref="T:Robocode.MessageEvent" />:          75
              <see cref="T:Robocode.RobotDeathEvent" />:       70
              <see cref="T:Robocode.BulletMissedEvent" />:     60
              <see cref="T:Robocode.BulletHitBulletEvent" />:  55
              <see cref="T:Robocode.BulletHitEvent" />:        50
              <see cref="T:Robocode.HitByBulletEvent" />:      40
              <see cref="T:Robocode.HitWallEvent" />:          30
              <see cref="T:Robocode.HitRobotEvent" />:         20
              <see cref="T:Robocode.ScannedRobotEvent" />:     10
              <see cref="T:Robocode.PaintEvent" />:             5
              <see cref="T:Robocode.DeathEvent" />:            -1 (reserved)
(Inherited from IAdvancedRobotPeer.)
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 methodGetHitByBulletEvents
Returns a list containing all HitByBulletEvents currently in the robot's queue. You might, for example, call this while processing another event.

Examples

foreach (HitByBulletEvent evnt inGetHitByBulletEvents())
{
    // do something with the event
}
(Inherited from IAdvancedRobotPeer.)
Public methodGetHitRobotEvents
Returns a list containing all HitRobotEvents currently in the robot's queue. You might, for example, call this while processing another event.

Examples

foreach (HitRobotEvent evnt inGetHitRobotEvents())
{
    // do something with the event
}
(Inherited from IAdvancedRobotPeer.)
Public methodGetHitWallEvents
Returns a list containing all HitWallEvents currently in the robot's queue. You might, for example, call this while processing another event.

Examples

foreach (HitWallEvent evnt inGetHitWallEvents())
{
    // do something with the event
}
(Inherited from IAdvancedRobotPeer.)
Public methodGetMessageEvents
Returns a list containing all MessageEvents currently in the robot's queue. You might, for example, call this while processing another event.

Examples

foreach (MessageEvent e in GetMessageEvents())
{
   // do something with e
}
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 methodGetRobotDeathEvents
Returns a list containing all RobotDeathEvents currently in the robot's queue. You might, for example, call this while processing another event.

Examples

foreach (RobotDeathEvent evnt inGetRobotDeathEvents())
{
    // do something with the event
}
(Inherited from IAdvancedRobotPeer.)
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 methodGetScannedRobotEvents
Returns a list containing all ScannedRobotEvents currently in the robot's queue. You might, for example, call this while processing another event.

Examples

foreach (ScannedRobotEvent evnt inGetScannedRobotEvents())
{
    // do something with the event
}
(Inherited from IAdvancedRobotPeer.)
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 methodGetStatusEvents
Returns a list containing all StatusEvents currently in the robot's queue. You might, for example, call this while processing another event.

Examples

foreach (StatusEvent evnt inGetStatusEvents())
{
    // do something with the event
}
(Inherited from IAdvancedRobotPeer.)
Public methodGetTeammates
Returns the names of all teammates, or null there is no teammates.

Examples

public void Run()
{
    // Prints Out all teammates 
    string[] teammates = GetTeammates();
    if (teammates != null)
    {
        foreach (string member in teammates)
        {
            Out.WriteLine(member);
        }
    }
}
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 methodIsAdjustGunForBodyTurn
Checks if the gun is set to adjust for the robot turning, i.e. to turn independent from the robot's body turn.

This call returns true if the gun is set to turn independent of the turn of the robot's body. Otherwise, false is returned, meaning that the gun is set to turn with the robot's body turn.
(Inherited from IStandardRobotPeer.)
Public methodIsAdjustRadarForBodyTurn
Checks if the radar is set to adjust for the gun turning, i.e. to turn independent from the gun's turn.

This call returns true if the radar is set to turn independent of the turn of the gun. Otherwise, false is returned, meaning that the radar is set to turn with the gun's turn.
(Inherited from IStandardRobotPeer.)
Public methodIsAdjustRadarForGunTurn
Checks if the radar is set to adjust for the robot turning, i.e. to turn independent from the robot's body turn.

This call returns true if the radar is set to turn independent of the turn of the robot. Otherwise, false is returned, meaning that the radar is set to turn with the robot's turn.
(Inherited from IStandardRobotPeer.)
Public methodIsTeammate
Checks if a given robot name is the name of one of your teammates.

Examples

public void OnScannedRobot(ScannedRobotEvent e)
{
    if (IsTeammate(e.Name)
    {
        return;
    }
    Fire(1);
}
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 methodRemoveCustomEvent
Removes a custom event that was previously added by calling AddCustomEvent(Condition).

Examples

AddCustomEvent(
    new Condition("triggerhit", (c) =>
    {
       return Energy <= trigger;
    }));

// Add our custom event based on our condition
AddCustomEvent(triggerHitCondition);
...
// do something with your robot
...
// Remove the custom event based on our condition
RemoveCustomEvent(triggerHitCondition);
(Inherited from IAdvancedRobotPeer.)
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 methodResume
Immediately resumes the movement you stopped by Stop(Boolean), if any.

This call executes immediately, and does not return until it is complete.
(Inherited from IStandardRobotPeer.)
Public methodSendMessage
Sends a message to one (or more) teammates.

Examples

public void Run()
{
    SendMessage("Sample.DroidBot", "I'm here!");
}
Public methodSetAdjustGunForBodyTurn
Sets the gun to turn independent from the robot's turn.

Ok, so this needs some explanation: The gun is mounted on the robot's body. So, normally, if the robot turns 90 degrees to the right, then the gun will turn with it as it is mounted on top of the robot's body. To compensate for this, you can call IsAdjustGunForBodyTurn(true). When this is set, the gun will turn independent from the robot's turn, i.e. the gun will compensate for the robot's body turn.

Note: This method is additive until you reach the maximum the gun can turn. The "adjust" is added to the amount you set for turning the robot, then capped by the physics of the game. If you turn infinite, then the adjust is ignored (and hence overridden).

Examples

Assuming both the robot and gun start Out facing up (0 degrees):
// Set gun to turn with the robot's turn
SetAdjustGunForBodyTurn(false); // This is the default
TurnBodyRight(Math.PI / 2);
// At this point, both the robot and gun are facing right (90 degrees)
TurnBodyLeft(Math.PI / 2);
// Both are back to 0 degrees
// Set gun to turn independent from the robot's turn
SetAdjustGunForBodyTurn(true);
TurnBodyRight(Math.PI / 2);
// At this point, the robot is facing right (90 degrees), but the gun is still facing up.
TurnBodyLeft(Math.PI / 2);
// Both are back to 0 degrees.
-- or --

Note: The gun compensating this way does count as "turning the gun". See SetAdjustRadarForGunTurn(Boolean) for details.
(Inherited from IStandardRobotPeer.)
Public methodSetAdjustRadarForBodyTurn
Sets the radar to turn independent from the robot's turn.

Ok, so this needs some explanation: The radar is mounted on the gun, and the gun is mounted on the robot's body. So, normally, if the robot turns 90 degrees to the right, the gun turns, as does the radar. Hence, if the robot turns 90 degrees to the right, then the gun and radar will turn with it as the radar is mounted on top of the gun. To compensate for this, you can call IsAdjustRadarForBodyTurn(true). When this is set, the radar will turn independent from the robot's turn, i.e. the radar will compensate for the robot's turn.

Note: This method is additive until you reach the maximum the radar can turn. The "adjust" is added to the amount you set for turning the gun, then capped by the physics of the game. If you turn infinite, then the adjust is ignored (and hence overridden).

Examples

Assuming the robot, gun, and radar all start Out facing up (0 degrees):
// Set radar to turn with the robots's turn
SetAdjustRadarForBodyTurn(false); // This is the default
TurnRight(Math.PI / 2);
// At this point, the body, gun, and radar are all facing right (90 degrees);
// Set radar to turn independent from the robot's turn
SetAdjustRadarForBodyTurn(true);
TurnRight(Math.PI / 2);
// At this point, the robot and gun are facing right (90 degrees), but the radar is still facing up.
-- or --
(Inherited from IStandardRobotPeer.)
Public methodSetAdjustRadarForGunTurn
Sets the radar to turn independent from the gun's turn.

Ok, so this needs some explanation: The radar is mounted on the robot's gun. So, normally, if the gun turns 90 degrees to the right, then the radar will turn with it as it is mounted on top of the gun. To compensate for this, you can call IsAdjustRadarForGunTurn(true). When this is set, the radar will turn independent from the robot's turn, i.e. the radar will compensate for the gun's turn.

Note: This method is additive until you reach the maximum the radar can turn. The "adjust" is added to the amount you set for turning the robot, then capped by the physics of the game. If you turn infinite, then the adjust is ignored (and hence overridden).

Examples

Assuming both the gun and radar start Out facing up (0 degrees):
// Set radar to turn with the gun's turn
SetAdjustRadarForGunTurn(false); // This is the default
TurnGunRight(Math.PI / 2);
// At this point, both the radar and gun are facing right (90 degrees);
// Set radar to turn independent from the gun's turn
SetAdjustRadarForGunTurn(true);
TurnGunRight(Math.PI / 2);
// At this point, the gun is facing right (90 degrees), but the radar is still facing up.
-- or -- Note: Calling IsAdjustRadarForGunTurn(bool) will automatically call SetAdjustRadarForBodyTurn(Boolean) with the same value, unless you have already called it earlier. This behavior is primarily for backward compatibility with older Robocode robots.
(Inherited from IStandardRobotPeer.)
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 methodSetEventPriority
Sets the priority of a class of events.

Events are sent to the onXXX handlers in order of priority. 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, where 100 is reserved and 80 is the default priority.

Examples

SetEventPriority("RobotDeathEvent", 15);

The default priorities are, from highest to lowest:
<see cref="T:Robocode.BattleEndedEvent" />:     100 (reserved)
              <see cref="T:Robocode.WinEvent" />:             100 (reserved)
              <see cref="T:Robocode.SkippedTurnEvent" />:     100 (reserved)
              <see cref="T:Robocode.StatusEvent" />:           99
              Key and mouse events:  98
              <see cref="T:Robocode.CustomEvent" />:           80 (default value)
              <see cref="T:Robocode.MessageEvent" />:          75
              <see cref="T:Robocode.RobotDeathEvent" />:       70
              <see cref="T:Robocode.BulletMissedEvent" />:     60
              <see cref="T:Robocode.BulletHitBulletEvent" />:  55
              <see cref="T:Robocode.BulletHitEvent" />:        50
              <see cref="T:Robocode.HitByBulletEvent" />:      40
              <see cref="T:Robocode.HitWallEvent" />:          30
              <see cref="T:Robocode.HitRobotEvent" />:         20
              <see cref="T:Robocode.ScannedRobotEvent" />:     10
              <see cref="T:Robocode.PaintEvent" />:             5
              <see cref="T:Robocode.DeathEvent" />:            -1 (reserved)

Note that you cannot change the priority for events with the special priority value -1 or 100 (reserved) as these event are system events. Also note that you cannot change the priority of CustomEvent. Instead you must change the priority of the condition(s) for your custom event(s).
(Inherited from IAdvancedRobotPeer.)
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 methodSetInterruptible
Call this during an event handler to allow new events of the same priority to restart the event handler.

Examples

public void OnScannedRobot(ScannedRobotEvent e)
{
    Fire(1);
    SetInterruptible(true);
    Move(100);  // If you see a robot while moving ahead, 
                // this handler will start from the top 
                // Without SetInterruptible(true), we wouldn't 
                // receive scan events at all! 
    // We'll only get here if we don't see a robot during the move.
    Out().WriteLine("Ok, I can't see anyone");
}
(Inherited from IAdvancedRobotPeer.)
Public methodSetMaxTurnRate
Sets the maximum turn rate of the robot measured in degrees if the robot should turn slower than MAX_TURN_RATE (10 degress/turn).
(Inherited from IAdvancedRobotPeer.)
Public methodSetMaxVelocity
Sets the maximum velocity of the robot measured in pixels/turn if the robot should move slower than MAX_VELOCITY (8 pixels/turn).
(Inherited from IAdvancedRobotPeer.)
Public methodSetMove
Sets the robot to move forward or backward by distance measured in pixels when the next execution takes place.

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

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. If 0 is given as input, the robot will stop its movement, but will have to decelerate till it stands still, and will thus not be able to stop its movement immediately, but eventually.

Examples

// Set the robot to move 50 pixels forward
SetMove(50);

// Set the robot to move 100 pixels backward 
// (overrides the previous order)
SetMove(-100);

...
// Executes the last SetMove()
Execute();
(Inherited from IAdvancedRobotPeer.)
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 methodSetResume
Sets the robot to Resume the movement stopped by Stop(Boolean) or SetStop(Boolean), if any.

This call returns immediately, and will not execute until you call Execute  or take an action that executes.
(Inherited from IAdvancedRobotPeer.)
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 methodSetStop
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).
(Inherited from IAdvancedRobotPeer.)
Public methodSetTurnBody
Sets the robot's body to turn right or left by radians when the next execution takes place.

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

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

// Set the robot's body to turn 180 degrees to the right
SetTurnBody(Math.PI);

// Set the robot's body to turn 90 degrees to the left instead of right 
// (overrides the previous order)
SetTurnBody(-Math.PI / 2);

...
// Executes the last SetTurnBody()
Execute();
(Inherited from IAdvancedRobotPeer.)
Public methodSetTurnGun
Sets the robot's gun to turn right or left by radians when the next execution takes place.

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

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

// Set the robot's gun to turn 180 degrees to the right
SetTurnGun(Math.PI);

// Set the robot's gun to turn 90 degrees to the left instead of right 
// (overrides the previous order)
SetTurnGun(-Math.PI / 2);

...
// Executes the last setTurnFun()
Execute();
(Inherited from IAdvancedRobotPeer.)
Public methodSetTurnRadar
Sets the robot's radar to turn right or left by radians when the next execution takes place.

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

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

Examples

// Set the robot's radar to turn 180 degrees to the right
SetTurnRadar(Math.PI);

// Set the robot's radar to turn 90 degrees to the left instead of right 
// (overrides the previous order)
SetTurnRadar(-Math.PI / 2);

...
// Executes the last SetTurnRadar()
Execute();
(Inherited from IAdvancedRobotPeer.)
Public methodStop
Immediately stops all movement, and saves it for a call to Resume . If there is already movement saved from a previous stop, you can overwrite it by calling Stop(true).
(Inherited from IStandardRobotPeer.)
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.)
Public methodTurnRadar
Immediately turns the robot's radar 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 radar's turn is 0.

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

Examples

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

// Afterwards, turn the robot's radar 90 degrees to the left
TurnRadar(-Math.PI / 2);
(Inherited from IStandardRobotPeer.)
Public methodWaitFor
Does not return until a condition is met, i.e. when a Test  returns true.

This call executes immediately.

See the Sample.Crazy robot for how this method can be used.
(Inherited from IAdvancedRobotPeer.)
Back to Top
See Also