Class BaseBot
Abstract bot class that takes care of communication between the bot and the server, and sends notifications through the event handlers. Most bots can inherit from this class to get access to basic methods.
Implements
Inherited Members
Namespace: Robocode.TankRoyale.BotApi
Assembly: Robocode.TankRoyale.BotApi.dll
Syntax
public abstract class BaseBot : IBaseBot
Constructors
| Edit this page View SourceBaseBot()
Constructor for initializing a new instance of the BaseBot class. This constructor should be used when both BotInfo and server URL is provided through environment variables, i.e., when starting up the bot using a booter. These environment variables must be set to provide the server URL and bot information, and are automatically set by the booter tool for Robocode.
Declaration
protected BaseBot()
Examples
Example of how to set the predefined environment variables used for connecting to the server:
- SERVER_URL=ws://localhost:7654
- SERVER_SECRET=xzoEeVbnBe5TGjCny0R1yQ
Example of how to set the environment variables that covers the BotInfo:
- BOT_NAME=MyBot
- BOT_VERSION=1.0
- BOT_AUTHORS=John Doe
- BOT_DESCRIPTION=Short description
- BOT_HOMEPAGE=https://somewhere.net/MyBot
- BOT_COUNTRY_CODES=us
- BOT_GAME_TYPES=melee,1v1
- BOT_PLATFORM=.Net 6.0
- BOT_PROG_LANG=C# 10.0
- BOT_INITIAL_POS=50,70, 270
These environment variables must be set prior to using this constructor:
- BOT_NAME
- BOT_VERSION
- BOT_AUTHORS
- BOT_AUTHORS, e.g. "John Doe, Jane Doe"
- BOT_COUNTRY_CODES, e.g. "se, no, dk"
- BOT_GAME_TYPES, e.g. "classic, melee, 1v1"
BOT_INITIAL_POS
variable is optional and should only be used for debugging.
The SERVER_SECRET must be set if the server requires a server secret for the bots trying to connect. Otherwise, the bot will be disconnected as soon as it attempts to connect to the server.
If the SERVER_URL is not set, then this default URL is used: ws://localhost:7654
| Edit this page View SourceBaseBot(BotInfo)
Constructor for initializing a new instance of the BaseBot class. This constructor assumes the server URL and secret is provided by the environment variables SERVER_URL and SERVER_SECRET.
Declaration
protected BaseBot(BotInfo botInfo)
Parameters
Type | Name | Description |
---|---|---|
BotInfo | botInfo | Is the bot info containing information about your bot. |
BaseBot(BotInfo, Uri)
Constructor for initializing a new instance of the BaseBot class.
Declaration
protected BaseBot(BotInfo botInfo, Uri serverUrl)
Parameters
Type | Name | Description |
---|---|---|
BotInfo | botInfo | Is the bot info containing information about your bot. |
Uri | serverUrl | Is the server URL |
BaseBot(BotInfo, Uri, string)
Constructor for initializing a new instance of the BaseBot class.
Declaration
protected BaseBot(BotInfo botInfo, Uri serverUrl, string serverSecret)
Parameters
Type | Name | Description |
---|---|---|
BotInfo | botInfo | Is the bot info containing information about your bot. |
Uri | serverUrl | Is the server URL |
string | serverSecret | Is the server secret for bots |
Properties
| Edit this page View SourceAdjustGunForBodyTurn
Sets the gun to adjust for the bot´s turn when setting the gun turn rate. So the gun behaves like it is turning independent of the bot´s turn.
Ok, so this needs some explanation: The gun is mounted on the bot´s body. So, normally, if the bot turns 90 degrees to the right, then the gun will turn with it as it is mounted on top of the bot´s body. To compensate for this, you can adjust the gun for the body turning. When this is set, the gun will turn independent of the body turning.
note
This property is additive until you reach the maximum the gun can turn MaxGunTurnRate. The "adjust" is added to the amount, you set for turning the bot by the turn rate, then capped by the physics of the game.
The gun compensating this way does count as "turning the gun".
Declaration
public bool AdjustGunForBodyTurn { get; set; }
Property Value
Type | Description |
---|---|
bool |
|
See Also
| Edit this page View SourceAdjustRadarForBodyTurn
Sets the radar to adjust for the body's turn when setting the radar turn rate. So the radar behaves like it is turning independent of the body's turn.
Ok, so this needs some explanation: The radar is mounted on the gun, and the gun is mounted on the bot´s body. So, normally, if the bot turns 90 degrees to the right, the gun turns, as does the radar. Hence, if the bot 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 adjust the radar for the body turn. When this is set, the radar will turn independent of the body's turn.
note
This property is additive until you reach the maximum the radar can turn MaxRadarTurnRate. The "adjust" is added to the amount, you set for turning the body by the body turn rate, then capped by the physics of the game.
The radar compensating this way does count as "turning the radar".
Declaration
public bool AdjustRadarForBodyTurn { get; set; }
Property Value
Type | Description |
---|---|
bool |
|
See Also
| Edit this page View SourceAdjustRadarForGunTurn
Sets the radar to adjust for the gun's turn when setting the radar turn rate. So the radar behaves like it is turning independent of the gun's turn.
Ok, so this needs some explanation: The radar is mounted on the 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 adjust the radar for the gun turn. When this is set, the radar will turn independent of the gun turning.
note
This property is additive until you reach the maximum the radar can turn MaxRadarTurnRate. The "adjust" is added to the amount, you set for turning the gun by the gun turn rate, then capped by the physics of the game.
When the radar compensates this way it counts as "turning the radar", even when it is not explicitly turned by calling a method for turning the radar.
When the radar compensates this way it counts as "turning the radar", even when it is not explicitly turned by calling a method for turning the radar.
note
This method automatically disables fire assistance when set to true
, and automatically
enables fire assistance when set to false
. This is not the case for AdjustGunForBodyTurn and AdjustRadarForBodyTurn.
Read more about fire assistance with the SetFireAssist(bool) method.
Declaration
public bool AdjustRadarForGunTurn { get; set; }
Property Value
Type | Description |
---|---|
bool |
See Also
| Edit this page View SourceArenaHeight
Height of the arena measured in unit.
First available when the game has started.
Declaration
public int ArenaHeight { get; }
Property Value
Type | Description |
---|---|
int | The arena height measured in units |
ArenaWidth
Width of the arena measured in unit.
First available when the game has started.
Declaration
public int ArenaWidth { get; }
Property Value
Type | Description |
---|---|
int | The arena width measured in units |
BodyColor
The color of the body. Colors can (only) be changed each turn.
Declaration
public Color BodyColor { get; set; }
Property Value
Type | Description |
---|---|
Color | Is the color of the body or |
Examples
BodyColor = Color.RED; // the red color BodyColor = new Color(255, 0, 0); // also the red color BodyColor = Color.fromHexTriplet("F00"); // and also the red color
| Edit this page View SourceBulletColor
The color of the fired bullets. Colors can (only) be changed each turn.
Note that a fired bullet will not change is color when it has been fired. But new bullets fired after setting the bullet color will get the new color.
Declaration
public Color BulletColor { get; set; }
Property Value
Type | Description |
---|---|
Color | Is the color of the fired bullets or |
Examples
BulletColor = Color.RED; // the red color BulletColor = new Color(255, 0, 0); // also the red color BulletColor = Color.fromHexTriplet("F00"); // and also the red color
| Edit this page View SourceBulletStates
Current bullet states. Keeps track of all the bullets fired by the bot, which are still active on the arena.
Declaration
public IEnumerable<BulletState> BulletStates { get; }
Property Value
Type | Description |
---|---|
IEnumerable<BulletState> | The current bullet states. |
Direction
Current driving direction of the bot in degrees.
Declaration
public double Direction { get; }
Property Value
Type | Description |
---|---|
double | The current driving direction of the bot. |
EnemyCount
Number of enemies left in the current round.
Declaration
public int EnemyCount { get; }
Property Value
Type | Description |
---|---|
int |
Energy
Current energy level. When the energy level is positive, the bot is alive and active. When the energy level is 0, the bot is still alive but disabled. If the bot becomes disabled it will not be able to move or take any action. If negative, the bot has been defeated.
Declaration
public double Energy { get; }
Property Value
Type | Description |
---|---|
double | The current energy level. |
Events
Events that remain to be processed in event handlers, which is useful to see the events that remain from event handlers being called before other event handlers. But also to access events have not been handled yet due to the bot skipping turns.
Declaration
public IList<BotEvent> Events { get; }
Property Value
Type | Description |
---|---|
IList<BotEvent> | An ordered list of all the events remaining to be handled for the current and previous (skipped) turns. The events are being sorted so that older events get listed first, and secondly sorted on event priority. |
Firepower
The firepower.
Declaration
public double Firepower { get; }
Property Value
Type | Description |
---|---|
double | The firepower |
GameType
Game type, e.g. "melee" or "1v1".
First available when the game has started.
Declaration
public string GameType { get; }
Property Value
Type | Description |
---|---|
string | The game type |
GunColor
The color of the gun. Colors can (only) be changed each turn.
Declaration
public Color GunColor { get; set; }
Property Value
Type | Description |
---|---|
Color | Is the color of the gun or |
Examples
GunColor = Color.RED; // the red color GunColor = new Color(255, 0, 0); // also the red color GunColor = Color.fromHexTriplet("F00"); // and also the red color
| Edit this page View SourceGunCoolingRate
Gun cooling rate. The gun needs to cool down to a gun heat of zero before the gun can fire. The gun cooling rate determines how fast the gun cools down. That is, the gun cooling rate is subtracted from the gun heat each turn until the gun heat reaches zero.
First available when the game has started.
Declaration
public double GunCoolingRate { get; }
Property Value
Type | Description |
---|---|
double | The gun cooling rate |
See Also
| Edit this page View SourceGunDirection
Current direction of the gun in degrees.
Declaration
public double GunDirection { get; }
Property Value
Type | Description |
---|---|
double | The current gun direction of the bot. |
GunHeat
Current gun heat. When the is fired it gets heated and will not be able to fire before it has been cooled down. The gun is cooled down when the gun heat is zero.
When the gun has fired the gun heat is set to 1 + (firepower / 5) and will be cooled down by the gun cooling rate.
Declaration
public double GunHeat { get; }
Property Value
Type | Description |
---|---|
double | The current gun heat. |
See Also
| Edit this page View SourceGunTurnRate
Set or get the turn rate of the gun, which can be positive and negative. The gun turn rate is measured in degrees per turn. The turn rate is added to the current turn direction of the gun. But it is also added to the current direction of the radar. This is because the radar is mounted on the gun, and hence moves with the gun. You can compensate for the turn rate of the gun by subtracting the turn rate of the gun from the turn rate of the radar. But be aware that the turn limits defined for the radar cannot be exceeded.
The gun turn rate is truncated to MaxGunTurnRate if the gun turn rate exceeds this value.
If this property is set multiple times, the last value set before Go() counts.
Declaration
public virtual double GunTurnRate { get; set; }
Property Value
Type | Description |
---|---|
double | The turn rate of the gun. |
See Also
| Edit this page View SourceInterruptible
Set this property during an event handler to control continuing or restarting the event handler, when a new event occurs again for the same event handler while processing an earlier event.
Declaration
public bool Interruptible { set; }
Property Value
Type | Description |
---|---|
bool |
|
Examples
Example:
public void OnScannedBot(ScannedBotEvent e)
{
Fire(1);
Interruptible = true;
Forward(100); // When a new bot is scanned while moving forward this handler will restart
// from the top as this event handler has been set to be interruptible
// right after firing. Without Interruptible = true, new scan events
// would not be triggered while moving forward.
// We'll only get here if we do not see a robot during the move.
Console.WriteLine("No bots were scanned");
}
|
Edit this page
View Source
IsDisabled
Specifies if the bot is disabled, i.e., when the energy is zero. When the bot is disabled, it is not able to take any action like movement, turning, and firing.
Declaration
public bool IsDisabled { get; }
Property Value
Type | Description |
---|---|
bool |
|
IsStopped
Checks if the movement has been stopped.
Declaration
public bool IsStopped { get; }
Property Value
Type | Description |
---|---|
bool |
|
See Also
| Edit this page View SourceMaxGunTurnRate
Sets or gets the maximum turn rate which applies to turn the gun to the left or right. The maximum turn rate must be an absolute value from 0 to MaxGunTurnRate, both values are included. If the input turn rate is negative, the max turn rate will be cut to zero. If the input turn rate is above MaxGunTurnRate, the max turn rate will be set to MaxGunTurnRate.
If for example the max gun turn rate is set to 5, then the gun will be able to turn left or right with a turn rate down to -5 degrees per turn when turning right and up to 5 degrees per turn when turning left.
This method will first be executed when Go() is called making it possible to call other set methods before execution. This makes it possible to set the bot to move, turn the body, radar, gun, and also fire the gun in parallel in a single turn when calling Go(). But notice that this is only possible to execute multiple methods in parallel by using setter methods only prior to calling Go().
If this method is called multiple times, the last call before Go() is executed, counts.
Declaration
public double MaxGunTurnRate { get; set; }
Property Value
Type | Description |
---|---|
double | The maximum turn rate of the gun. |
See Also
| Edit this page View SourceMaxInactivityTurns
The maximum number of inactive turns allowed the bot will become zapped by the game for being inactive. Inactive means that the bot has taken no action in several turns in a row.
First available when the game has started.
Declaration
public int? MaxInactivityTurns { get; }
Property Value
Type | Description |
---|---|
int? | The maximum number of allowed inactive turns. |
MaxRadarTurnRate
Sets or gets the maximum turn rate which applies to turn the radar to the left or right. The maximum turn rate must be an absolute value from 0 to MaxRadarTurnRate, both values are included. If the input turn rate is negative, the max turn rate will be cut to zero. If the input turn rate is above MaxRadarTurnRate, the max turn rate will be set to MaxRadarTurnRate.
If for example the max radar turn rate is set to 5, then the radar will be able to turn left or right with a turn rate down to -5 degrees per turn when turning right and up to 5 degrees per turn when turning left.
This method will first be executed when Go() is called making it possible to call other set methods before execution. This makes it possible to set the bot to move, turn the body, radar, gun, and also fire the gun in parallel in a single turn when calling Go(). But notice that this is only possible to execute multiple methods in parallel by using setter methods only prior to calling Go().
If this method is called multiple times, the last call before Go() is executed, counts.
Declaration
public double MaxRadarTurnRate { get; set; }
Property Value
Type | Description |
---|---|
double | The maximum turn rate of the radar. |
See Also
| Edit this page View SourceMaxSpeed
Sets or gets the maximum speed which applies when moving forward and backward. The maximum speed must be an absolute value from 0 to MaxSpeed, both values are included. If the input speed is negative, the max speed will be cut to zero. If the input speed is above MaxSpeed, the max speed will be set to MaxSpeed.
If for example the maximum speed is set to 5, then the bot will be able to move backwards with a speed down to -5 units per turn and up to 5 units per turn when moving forward.
This method will first be executed when Go() is called making it possible to call other set methods before execution. This makes it possible to set the bot to move, turn the body, radar, gun, and also fire the gun in parallel in a single turn when calling Go(). But notice that this is only possible to execute multiple methods in parallel by using setter methods only prior to calling Go().
If this method is called multiple times, the last call before Go() is executed, counts.
Declaration
public double MaxSpeed { get; set; }
Property Value
Type | Description |
---|---|
double | The maximum speed. |
MaxTurnRate
Sets or gets the maximum turn rate which applies to turn the bot to the left or right. The maximum turn rate must be an absolute value from 0 to MaxTurnRate, both values are included. If the input turn rate is negative, the max turn rate will be cut to zero. If the input turn rate is above MaxTurnRate, the max turn rate will be set to MaxTurnRate.
If for example the max turn rate is set to 5, then the bot will be able to turn left or right with a turn rate down to -5 degrees per turn when turning right, and up to 5 degrees per turn when turning left.
This method will first be executed when Go() is called making it possible to call other set methods before execution. This makes it possible to set the bot to move, turn the body, radar, gun, and also fire the gun in parallel in a single turn when calling Go(). But notice that this is only possible to execute multiple methods in parallel by using setter methods only prior to calling Go().
If this method is called multiple times, the last call before Go() is executed, counts.
Declaration
public double MaxTurnRate { get; set; }
Property Value
Type | Description |
---|---|
double | The maximum turn rate of the bot. |
See Also
| Edit this page View SourceMyId
Unique id of this bot, which is available when the game has started.
Declaration
public int MyId { get; }
Property Value
Type | Description |
---|---|
int | The unique id of this bot. |
NumberOfRounds
The number of rounds in a battle.
First available when the game has started.
Declaration
public int NumberOfRounds { get; }
Property Value
Type | Description |
---|---|
int | The number of rounds in a battle. |
RadarColor
The color of the radar. Colors can (only) be changed each turn.
Declaration
public Color RadarColor { get; set; }
Property Value
Type | Description |
---|---|
Color | Is the color of the radar or |
Examples
RadarColor = Color.RED; // the red color RadarColor = new Color(255, 0, 0); // also the red color RadarColor = Color.fromHexTriplet("F00"); // and also the red color
| Edit this page View SourceRadarDirection
Current direction of the radar in degrees.
Declaration
public double RadarDirection { get; }
Property Value
Type | Description |
---|---|
double | The current radar direction of the bot. |
RadarTurnRate
Set or get the turn rate of the radar, which can be positive and negative. The radar turn rate is measured in degrees per turn. The turn rate is added to the current direction of the radar. Note that besides the turn rate of the radar, the turn rates of the bot and gun are also added to the radar direction, as the radar moves with the gun, which is mounted on the gun that moves with the body. You can compensate for the turn rate of the gun by subtracting the turn rate of the bot and gun from the turn rate of the radar. But be aware that the turn limits defined for the radar cannot be exceeded.
The radar turn rate is truncated to MaxRadarTurnRate if the radar turn rate exceeds this value.
If this property is set multiple times, the last value set before Go() counts.
Declaration
public virtual double RadarTurnRate { get; set; }
Property Value
Type | Description |
---|---|
double | The turn rate of the radar. |
See Also
| Edit this page View SourceRoundNumber
Current round number.
Declaration
public int RoundNumber { get; }
Property Value
Type | Description |
---|---|
int | The current round number. |
ScanColor
The color of the scan arc. Colors can (only) be changed each turn.
Declaration
public Color ScanColor { get; set; }
Property Value
Type | Description |
---|---|
Color | Is the color of the scan arc or |
Examples
ScanColor = Color.RED; // the red color ScanColor = new Color(255, 0, 0); // also the red color ScanColor = Color.fromHexTriplet("F00"); // and also the red color
| Edit this page View SourceSpeed
The current speed measured in units per turn. If the speed is positive, the bot moves forward. If negative, the bot moves backward. Zero speed means that the bot is not moving from its current position.
Declaration
public double Speed { get; }
Property Value
Type | Description |
---|---|
double | The current speed. |
TargetSpeed
Set or get the target speed for the bot in units per turn. The target speed is the speed you want to achieve eventually, which could take one to several turns depending on the current speed. For example, if the bot is moving forward with max speed, and then must change to move backward at full speed, the bot will have to first decelerate/brake its positive speed (moving forward). When passing speed of zero, it will then have to accelerate back to achieve max negative speed.
note
Acceleration is 1 unit per turn and deceleration/braking is faster than acceleration as it is -2 unit per turn. Deceleration is negative as it is added to the speed and hence needs to be negative when slowing down.
note
The target speed is truncated to MaxSpeed if the target speed exceeds this value.
If this property is set multiple times, the last value set before Go() counts.
Declaration
public double TargetSpeed { get; set; }
Property Value
Type | Description |
---|---|
double | The target speed. |
TeammateIds
Returns the ids of all teammates.
Declaration
public ICollection<int> TeammateIds { get; }
Property Value
Type | Description |
---|---|
ICollection<int> | The ids of all teammates if the bot is participating in a team or an empty collection if the bot is not in a team. |
See Also
| Edit this page View SourceTimeLeft
The number of microseconds left of this turn before the bot will skip the turn. Make sure to call Go() before the time runs out.
Declaration
public int TimeLeft { get; }
Property Value
Type | Description |
---|---|
int | The amount of time left in microseconds. |
See Also
| Edit this page View SourceTracksColor
The color of the tracks. Colors can (only) be changed each turn.
Declaration
public Color TracksColor { get; set; }
Property Value
Type | Description |
---|---|
Color | Is the color of the tracks or |
Examples
TracksColor = Color.RED; // the red color TracksColor = new Color(255, 0, 0); // also the red color TracksColor = Color.fromHexTriplet("F00"); // and also the red color
| Edit this page View SourceTurnNumber
Current turn number.
Declaration
public int TurnNumber { get; }
Property Value
Type | Description |
---|---|
int | The current turn number. |
TurnRate
Set or get the turn rate of the bot, which can be positive and negative. The turn rate is measured in degrees per turn. The turn rate is added to the current direction of the bot. But it is also added to the current direction of the gun and radar. This is because the gun is mounted on the body, and hence turns with the body. The radar is mounted on the gun and hence moves with the gun. You can compensate for the turn rate of the bot by subtracting the turn rate of the bot from the turn rate of the gun and radar. But be aware that the turn limits defined for the gun and radar cannot be exceeded.
The turn rate is truncated to MaxTurnRate if the turn rate exceeds this value.
If this property is set multiple times, the last value set before Go() counts.
Declaration
public virtual double TurnRate { get; set; }
Property Value
Type | Description |
---|---|
double | The turn rate of the bot |
See Also
| Edit this page View SourceTurnTimeout
Turn timeout in microseconds (1 / 1,000,000 second). The turn timeout is important as the bot needs to take action by calling Go() before the turn timeout occurs. As soon as the TickEvent is triggered, i.e. when OnTick(TickEvent) is called, you need to call Go() to take action before the turn timeout occurs. Otherwise, your bot will skip a turn and receive a OnSkippedTurn(SkippedTurnEvent) for each turn where Go() is called too late.
First available when the game has started.
Declaration
public int TurnTimeout { get; }
Property Value
Type | Description |
---|---|
int | The turn timeout in microseconds. |
See Also
| Edit this page View SourceTurretColor
The color of the gun turret. Colors can (only) be changed each turn.
Declaration
public Color TurretColor { get; set; }
Property Value
Type | Description |
---|---|
Color | Is the color of the gun turret or |
Examples
TurretColor = Color.RED; // the red color TurretColor = new Color(255, 0, 0); // also the red color TurretColor = Color.fromHexTriplet("F00"); // and also the red color
| Edit this page View SourceVariant
The game variant, which is "Tank Royale".
Declaration
public string Variant { get; }
Property Value
Type | Description |
---|---|
string | The game variant of Robocode. |
Version
Game version, e.g. "1.0.0".
Declaration
public string Version { get; }
Property Value
Type | Description |
---|---|
string | The game version. |
X
Current X coordinate of the center of the bot.
Declaration
public double X { get; }
Property Value
Type | Description |
---|---|
double | Current X coordinate of the bot. |
Y
Current Y coordinate of the center of the bot.
Declaration
public double Y { get; }
Property Value
Type | Description |
---|---|
double | Current Y coordinate of the bot. |
Methods
| Edit this page View SourceAddCustomEvent(Condition)
Adds a event handler that will be automatically triggered OnCustomEvent(CustomEvent) when the Test() returns true.
Declaration
public bool AddCustomEvent(Condition condition)
Parameters
Type | Name | Description |
---|---|---|
Condition | condition | Is the condition that must be met to trigger the custom event. |
Returns
Type | Description |
---|---|
bool |
See Also
| Edit this page View SourceBearingTo(double, double)
Calculates the bearing (delta angle) between the bot´s coordinates and direction and the direction to the point x,y.
Declaration
public virtual double BearingTo(double x, double y)
Parameters
Type | Name | Description |
---|---|---|
double | x | Is the x coordinate of the point. |
double | y | Is the y coordinate of the point. |
Returns
Type | Description |
---|---|
double | The bearing to the point x,y in the range [-180,180[ |
BroadcastTeamMessage(object)
Broadcasts a message to all teammates.
When the message is send, it is serialized into a JSON representation, meaning that all public fields, and only public fields, are being serialized into a JSON representation as a DTO (data transfer object).
The maximum team message size limit is defined by TeamMessageMaxSize. This size is the size of the message when it is serialized into a JSON representation.
The maximum number of messages that can be send/broadcast per turn is defined by MaxNumberOfTeamMessagesPerTurn.
Declaration
public void BroadcastTeamMessage(object message)
Parameters
Type | Name | Description |
---|---|---|
object | message | The message to broadcast. |
Exceptions
Type | Condition |
---|---|
ArgumentException | if the size of the message exceeds the size limit. |
See Also
| Edit this page View SourceCalcBearing(double)
Calculates the bearing (delta angle) between the input direction and the direction of this bot.
Declaration
public virtual double CalcBearing(double direction)
Parameters
Type | Name | Description |
---|---|---|
double | direction | Is the input direction to calculate the bearing from. |
Returns
Type | Description |
---|---|
double | A bearing (delta angle) between the input direction and the direction of this bot. The bearing is a normalized angle in the range [-180,180[ |
See Also
| Edit this page View SourceCalcBulletSpeed(double)
Calculates the bullet speed given a fire power.
Declaration
public virtual double CalcBulletSpeed(double firepower)
Parameters
Type | Name | Description |
---|---|---|
double | firepower | Is the firepower. |
Returns
Type | Description |
---|---|
double | The bullet speed determined by the given firepower. |
CalcDeltaAngle(double, double)
Calculates the difference between two angles, i.e. the number of degrees from a source angle to a target angle. The delta angle will be in the range [-180,180]
Declaration
public virtual double CalcDeltaAngle(double targetAngle, double sourceAngle)
Parameters
Type | Name | Description |
---|---|---|
double | targetAngle | Is the target angle. |
double | sourceAngle | Is the source angle. |
Returns
Type | Description |
---|---|
double | The delta angle between a source angle and target angle. |
CalcGunBearing(double)
Calculates the bearing (delta angle) between the input direction and the direction of the gun.
Declaration
public virtual double CalcGunBearing(double direction)
Parameters
Type | Name | Description |
---|---|---|
double | direction | Is the input direction to calculate the bearing from. |
Returns
Type | Description |
---|---|
double | A bearing (delta angle) between the input direction and the direction of the gun. The bearing is a normalized angle in the range [-180,180[ |
See Also
| Edit this page View SourceCalcGunHeat(double)
Calculates gun heat after having fired the gun.
Declaration
public virtual double CalcGunHeat(double firepower)
Parameters
Type | Name | Description |
---|---|---|
double | firepower | Is the firepower used when firing the gun. |
Returns
Type | Description |
---|---|
double | The gun heat produced when firing the gun with the given firepower. |
CalcMaxTurnRate(double)
Calculates the maximum turn rate for a specific speed.
Declaration
public double CalcMaxTurnRate(double speed)
Parameters
Type | Name | Description |
---|---|---|
double | speed | Is the speed. |
Returns
Type | Description |
---|---|
double | The maximum turn rate determined by the given speed. |
CalcRadarBearing(double)
Calculates the bearing (delta angle) between the input direction and the direction of the radar.
Declaration
public virtual double CalcRadarBearing(double direction)
Parameters
Type | Name | Description |
---|---|---|
double | direction | Is the input direction to calculate the bearing from. |
Returns
Type | Description |
---|---|
double | A bearing (delta angle) between the input direction and the direction of the radar. The bearing is a normalized angle in the range [-180,180[ |
See Also
| Edit this page View SourceClearEvents()
Clears the remaining events that have not been processed yet.
Declaration
public void ClearEvents()
DirectionTo(double, double)
Calculates the direction (angle) from the bot´s coordinates to a point x,y.
Declaration
public virtual double DirectionTo(double x, double y)
Parameters
Type | Name | Description |
---|---|---|
double | x | Is the x coordinate of the point. |
double | y | Is the y coordinate of the point. |
Returns
Type | Description |
---|---|
double | The direction to the point x,y in the range [0,360[ |
DistanceTo(double, double)
Calculates the distance from the bot´s coordinates to a point x,y.
Declaration
public virtual double DistanceTo(double x, double y)
Parameters
Type | Name | Description |
---|---|---|
double | x | Is the x coordinate of the point. |
double | y | Is the y coordinate of the point. |
Returns
Type | Description |
---|---|
double | The distance to the point x,y. |
GetEventPriority(Type)
Returns the event priority for a specific event class.
Declaration
public virtual int GetEventPriority(Type eventType)
Parameters
Type | Name | Description |
---|---|---|
Type | eventType | Event type to get the event priority for. |
Returns
Type | Description |
---|---|
int | The event priority for a specific event class. |
Examples
Example:
int scannedBotEventPriority = GetPriority(ScannedBotEvent.GetType());
|
Edit this page
View Source
Go()
Commits the current commands (actions), which finalizes the current turn for the bot.
This method must be called once per turn to send the bot actions to the server and must be called before the turn timeout occurs. A turn timer is started when the GameStartedEvent and TickEvent occurs. If the Go() method is called too late,a turn timeout will occur and the SkippedTurnEvent will occur, which means that the bot has skipped all actions for the last turn. In this case, the server will continue executing the last actions received. This could be fatal for the bot due to loss of control over the bot. So make sure that Go() is called before the turn ends.
The commands executed when Go() is called are set by setting these properties prior to calling the Go() method: TurnRate, GunTurnRate, RadarTurnRate, TargetSpeed, and SetFire(double).
Declaration
public void Go()
See Also
| Edit this page View SourceGunBearingTo(double, double)
Calculates the bearing (delta angle) between the bot´s gun and direction and the direction to the point x,y.
Declaration
public virtual double GunBearingTo(double x, double y)
Parameters
Type | Name | Description |
---|---|---|
double | x | Is the x coordinate of the point. |
double | y | Is the y coordinate of the point. |
Returns
Type | Description |
---|---|
double | The bearing to the point x,y in the range [-180,180[ |
IsTeammate(int)
Checks if the provided bot id is a teammate or not.
Declaration
public bool IsTeammate(int botId)
Parameters
Type | Name | Description |
---|---|---|
int | botId | The id of the bot to check for |
Returns
Type | Description |
---|---|
bool |
|
Examples
Example:
public override void OnScannedBot(ScannedBotEvent e)
{
if (IsTeammate(e.ScannedBotId)
{
return; // don't do anything by leaving
}
Fire(1);
}
See Also
| Edit this page View SourceNormalizeAbsoluteAngle(double)
Normalizes an angle to an absolute angle into the range [0,360[
Declaration
public virtual double NormalizeAbsoluteAngle(double angle)
Parameters
Type | Name | Description |
---|---|---|
double | angle | Is the angle to normalize. |
Returns
Type | Description |
---|---|
double | The normalized absolute angle. |
NormalizeRelativeAngle(double)
Normalizes an angle to an relative angle into the range [-180,180[
Declaration
public virtual double NormalizeRelativeAngle(double angle)
Parameters
Type | Name | Description |
---|---|---|
double | angle | Is the angle to normalize. |
Returns
Type | Description |
---|---|
double | The normalized relative angle. |
OnBotDeath(BotDeathEvent)
The event handler triggered when another bot has died.
Declaration
public virtual void OnBotDeath(BotDeathEvent botDeathEvent)
Parameters
Type | Name | Description |
---|---|---|
BotDeathEvent | botDeathEvent | Event details from the game. |
OnBulletFired(BulletFiredEvent)
The event handler triggered when the bot has fired a bullet.
Declaration
public virtual void OnBulletFired(BulletFiredEvent bulletFiredEvent)
Parameters
Type | Name | Description |
---|---|---|
BulletFiredEvent | bulletFiredEvent | Event details from the game. |
OnBulletHit(BulletHitBotEvent)
The event handler triggered when the bot has hit another bot with a bullet.
Declaration
public virtual void OnBulletHit(BulletHitBotEvent bulletHitBotEvent)
Parameters
Type | Name | Description |
---|---|---|
BulletHitBotEvent | bulletHitBotEvent | Event details from the game. |
OnBulletHitBullet(BulletHitBulletEvent)
The event handler triggered when a bullet fired from the bot has collided with another bullet.
Declaration
public virtual void OnBulletHitBullet(BulletHitBulletEvent bulletHitBulletEvent)
Parameters
Type | Name | Description |
---|---|---|
BulletHitBulletEvent | bulletHitBulletEvent | Event details from the game. |
OnBulletHitWall(BulletHitWallEvent)
The event handler triggered when a bullet has hit a wall.
Declaration
public virtual void OnBulletHitWall(BulletHitWallEvent bulletHitWallEvent)
Parameters
Type | Name | Description |
---|---|---|
BulletHitWallEvent | bulletHitWallEvent | Event details from the game. |
OnConnected(ConnectedEvent)
The event handler triggered when connected to the server.
Declaration
public virtual void OnConnected(ConnectedEvent connectedEvent)
Parameters
Type | Name | Description |
---|---|---|
ConnectedEvent | connectedEvent | Event details from the game. |
OnConnectionError(ConnectionErrorEvent)
The event handler triggered when a connection error occurs.
Declaration
public virtual void OnConnectionError(ConnectionErrorEvent connectionErrorEvent)
Parameters
Type | Name | Description |
---|---|---|
ConnectionErrorEvent | connectionErrorEvent | Event details from the game. |
OnCustomEvent(CustomEvent)
The event handler triggered when some condition has been met. Use the Name of the condition when you need to differentiate between different types of conditions received with this event handler.
Declaration
public virtual void OnCustomEvent(CustomEvent customEvent)
Parameters
Type | Name | Description |
---|---|---|
CustomEvent | customEvent | Event details from the game. |
OnDeath(DeathEvent)
The event handler triggered when this bot has died.
Declaration
public virtual void OnDeath(DeathEvent botDeathEvent)
Parameters
Type | Name | Description |
---|---|---|
DeathEvent | botDeathEvent |
OnDisconnected(DisconnectedEvent)
The event handler triggered when disconnected from the server.
Declaration
public virtual void OnDisconnected(DisconnectedEvent disconnectedEvent)
Parameters
Type | Name | Description |
---|---|---|
DisconnectedEvent | disconnectedEvent | Event details from the game. |
OnGameEnded(GameEndedEvent)
The event handler triggered when the game has ended.
Declaration
public virtual void OnGameEnded(GameEndedEvent gameEndedEvent)
Parameters
Type | Name | Description |
---|---|---|
GameEndedEvent | gameEndedEvent | Event details from the game. |
OnGameStarted(GameStartedEvent)
The event handler triggered when the game has started.
Declaration
public virtual void OnGameStarted(GameStartedEvent gameStatedEvent)
Parameters
Type | Name | Description |
---|---|---|
GameStartedEvent | gameStatedEvent | Event details from the game. |
OnHitBot(HitBotEvent)
The event handler triggered when the bot has collided with another bot.
Declaration
public virtual void OnHitBot(HitBotEvent botHitBotEvent)
Parameters
Type | Name | Description |
---|---|---|
HitBotEvent | botHitBotEvent | Event details from the game. |
OnHitByBullet(HitByBulletEvent)
The event handler triggered when the bot has been hit by a bullet.
Declaration
public virtual void OnHitByBullet(HitByBulletEvent bulletHitBotEvent)
Parameters
Type | Name | Description |
---|---|---|
HitByBulletEvent | bulletHitBotEvent |
OnHitWall(HitWallEvent)
The event handler triggered when the bot has hit a wall.
Declaration
public virtual void OnHitWall(HitWallEvent botHitWallEvent)
Parameters
Type | Name | Description |
---|---|---|
HitWallEvent | botHitWallEvent | Event details from the game. |
OnRoundEnded(RoundEndedEvent)
The event handler triggered when a round has ended.
Declaration
public virtual void OnRoundEnded(RoundEndedEvent roundEndedEvent)
Parameters
Type | Name | Description |
---|---|---|
RoundEndedEvent | roundEndedEvent | Event details from the game. |
OnRoundStarted(RoundStartedEvent)
The event handler triggered when a new round has started.
Declaration
public virtual void OnRoundStarted(RoundStartedEvent roundStatedEvent)
Parameters
Type | Name | Description |
---|---|---|
RoundStartedEvent | roundStatedEvent |
OnScannedBot(ScannedBotEvent)
The event handler triggered when the bot has scanned another bot.
Declaration
public virtual void OnScannedBot(ScannedBotEvent scannedBotEvent)
Parameters
Type | Name | Description |
---|---|---|
ScannedBotEvent | scannedBotEvent | Event details from the game. |
OnSkippedTurn(SkippedTurnEvent)
The event handler triggered when the bot has skipped a turn. This event occurs if the bot did not take any action in a specific turn. That is, Go() was not called before the turn timeout occurred for the turn. If the bot does not take action for multiple turns in a row, it will receive a SkippedTurnEvent for each turn where it did not take action. When the bot is skipping a turn, the server did not receive the message from the bot, and the server will use the newest received instructions for target speed, turn rates, firing, etc.
Declaration
public virtual void OnSkippedTurn(SkippedTurnEvent skippedTurnEvent)
Parameters
Type | Name | Description |
---|---|---|
SkippedTurnEvent | skippedTurnEvent | Event details from the game. |
OnTeamMessage(TeamMessageEvent)
The event handler triggered when the bot has received a message from a teammate.
Declaration
public virtual void OnTeamMessage(TeamMessageEvent teamMessageEvent)
Parameters
Type | Name | Description |
---|---|---|
TeamMessageEvent | teamMessageEvent | Event details from the game. |
OnTick(TickEvent)
The event handler triggered when a game tick event occurs, i.e., when a new turn in a round has started. When this handler is triggered, your bot must figure out the next action to take and call Go() when it needs to commit the action to the server.
Declaration
public virtual void OnTick(TickEvent tickEvent)
Parameters
Type | Name | Description |
---|---|---|
TickEvent | tickEvent | Event details from the game. |
OnWonRound(WonRoundEvent)
The event handler triggered when the bot has won a round.
Declaration
public virtual void OnWonRound(WonRoundEvent wonRoundEvent)
Parameters
Type | Name | Description |
---|---|---|
WonRoundEvent | wonRoundEvent | Event details from the game. |
RadarBearingTo(double, double)
Calculates the bearing (delta angle) between the bot´s radar and direction and the direction to the point x,y.
Declaration
public virtual double RadarBearingTo(double x, double y)
Parameters
Type | Name | Description |
---|---|---|
double | x | Is the x coordinate of the point. |
double | y | Is the y coordinate of the point. |
Returns
Type | Description |
---|---|
double | The bearing to the point x,y in the range [-180,180[ |
RemoveCustomEvent(Condition)
Removes triggering an custom event handler for a specific condition that was previously added with AddCustomEvent(Condition).
Declaration
public bool RemoveCustomEvent(Condition condition)
Parameters
Type | Name | Description |
---|---|---|
Condition | condition | is the condition that was previously added with AddCustomEvent(Condition) |
Returns
Type | Description |
---|---|
bool |
See Also
| Edit this page View SourceSendTeamMessage(int, object)
Sends a message to a specific teammate.
When the message is send, it is serialized into a JSON representation, meaning that all public fields, and only public fields, are being serialized into a JSON representation as a DTO (data transfer object).
The maximum team message size limit is defined by TeamMessageMaxSize. This size is the size of the message when it is serialized into a JSON representation.
The maximum number of messages that can be send/broadcast per turn is defined by MaxNumberOfTeamMessagesPerTurn.
Declaration
public void SendTeamMessage(int teammateId, object message)
Parameters
Type | Name | Description |
---|---|---|
int | teammateId | The id of the teammate to send the message to. |
object | message | The message to broadcast. |
Exceptions
Type | Condition |
---|---|
ArgumentException | if the size of the message exceeds the size limit. |
See Also
| Edit this page View SourceSetEventPriority(Type, int)
Changes the event priority for an event class. The event priority is used for determining which event types (classes) that must be fired and handled before others. Events with higher priorities will be handled before events with lower priorities.
Declaration
public virtual void SetEventPriority(Type eventType, int priority)
Parameters
Type | Name | Description |
---|---|---|
Type | eventType | Event type to change the event priority for. |
int | priority | The new priority. Typically, a positive number from 1 to 150. The greater value, the higher priority. |
SetFire(double)
Sets the gun to fire in the direction that the gun is pointing with the specified firepower.
Firepower is the amount of energy your bot will spend on firing the gun. This means that the bot will lose power on firing the gun where the energy loss is equal to the firepower. You cannot spend more energy than available from your bot.
The bullet power must be greater than MinFirepower and the gun heat zero before the gun can fire.
If the bullet hits an opponent bot, you will gain energy from the bullet hit.When hitting another bot, your bot will be rewarded and retrieve an energy boost of 3x firepower.
The gun will only fire when the firepower is at MinFirepower or higher. If the firepower is more thanMaxFirepower the power will be truncated to the max firepower.
Whenever the gun is fired, the gun is heated and needs to cool down before it can fire again. The gun heat must be zero before the gun is able to fire (see GunHeat. The gun heat generated by firing the gun is 1 + (firepower / 5). Hence, the more firepower used the longer it takes to cool down the gun. The gun cooling rate can be read by calling GunCoolingRate.
The amount of energy used for firing the gun is subtracted from the bot´s total energy. The amount of damage dealt by a bullet hitting another bot is 4x firepower, and if the firepower is greater than 1 it will do an additional 2 x (firepower - 1) damage.
note
The gun will automatically keep firing at any turn as soon as the gun heat reaches zero. It is possible to disable the gun firing by setting the firepower to zero.
The firepower is truncated to 0 and MaxFirepower if the firepower exceeds this value.
If this property is set multiple times, the last value set before Go() counts.
Declaration
public bool SetFire(double firepower)
Parameters
Type | Name | Description |
---|---|---|
double | firepower | The new firepower. |
Returns
Type | Description |
---|---|
bool |
|
See Also
| Edit this page View SourceSetFireAssist(bool)
Enables or disables fire assistance explicitly. Fire assistance is useful for bots with limited aiming capabilities as it will help the bot by firing directly at a scanned bot when the gun is fired, which is a very simple aiming strategy.
When fire assistance is enabled the gun will fire directly towards the center of the scanned bot when all these conditions are met:
- The gun is fired SetFire(double) and Fire(double)
- The radar is scanning a bot when firing the gun (OnScannedBot(ScannedBotEvent), SetRescan(), Rescan())
- The gun and radar are pointing in the exact the same direction. You can set
AdjustRadarForGunTurn=false
to align the gun and radar and make sure not to turn the radar beside the gun.
AdvancedRobot
got fire assistance per default as the gun and
radar cannot be moved independently of each other. (The AdvancedRobot
allows the body, gun,
and radar to move independent of each other).
Declaration
public void SetFireAssist(bool enable)
Parameters
Type | Name | Description |
---|---|---|
bool | enable | Enables fire assistance when set to |
SetRescan()
Sets the bot to rescan with the radar. This method is useful if the radar has not turned, and hence will not automatically scan bots. The last radar direction and sweep angle will be used for scanning for bots.
Declaration
public void SetRescan()
SetResume()
Sets the bot to scan (again) with the radar. This method is useful if the radar has not been turning and thereby will not be able to automatically scan bots. This method is useful when the bot movement has stopped, e.g. when Stop() has been called. The last radar direction and sweep angle will be used for rescanning for bots.
This method will first be executed when Go() is called making it possible to call other set methods before execution. This makes it possible to set the bot to move, turn the body, radar, gun, and also fire the gun in parallel in a single turn when calling Go(). But notice that this is only possible to execute multiple methods in parallel by using setter methods only prior to calling Go().
Declaration
public void SetResume()
See Also
| Edit this page View SourceSetStop()
Set the bot to stop all movement including turning the gun and radar. The remaining movement is saved for a call to SetResume(). This method has no effect, if it has already been called.
This method will first be executed when Go() is called making it possible to call other set methods before execution. This makes it possible to set the bot to move, turn the body, radar, gun, and also fire the gun in parallel in a single turn when calling Go(). But notice that this is only possible to execute multiple methods in parallel by using setter methods only prior to calling Go().
Declaration
public void SetStop()
See Also
| Edit this page View SourceSetStop(bool)
Set the bot to stop all movement including turning the gun and radar. The remaining movement is saved for a call to SetResume().
This method will first be executed when Go() is called making it possible to call other set methods before execution. This makes it possible to set the bot to move, turn the body, radar, gun, and also fire the gun in parallel in a single turn when calling Go(). But notice that this is only possible to execute multiple methods in parallel by using setter methods only prior to calling Go().
Declaration
public void SetStop(bool overwrite)
Parameters
Type | Name | Description |
---|---|---|
bool | overwrite | overwrite is set to |
See Also
| Edit this page View SourceStart()
The method used to start running the bot. You should call this method from the main method or similar.
Declaration
public void Start()
Examples
This sample shows how to call the Start() method.
static void Main(string[] args)
{
// create myBot
...
myBot.Start();
}