Interface IBaseBot
-
-
Field Summary
Fields Modifier and Type Field Description static intMAX_NUMBER_OF_TEAM_MESSAGES_PER_TURNThe maximum number of team messages that can be sent per turn, which is 10 messages.static intTEAM_MESSAGE_MAX_SIZEThe maximum size of a team message, which is 32 KB (32.786 bytes).
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description booleanaddCustomEvent(Condition condition)Adds an event handler that will be automatically triggeredonCustomEvent(dev.robocode.tankroyale.botapi.events.CustomEvent)when theCondition.test()returnstrue.default doublebearingTo(double x, double y)Calculates the bearing (delta angle) between the current direction of the bot's body and the direction to the point x,y.voidbroadcastTeamMessage(Object message)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 byTEAM_MESSAGE_MAX_SIZE, which is set to 32768 bytes.default doublecalcBearing(double direction)Calculates the bearing (delta angle) between the input direction and the direction of this bot.doublecalcBulletSpeed(double firepower)Calculates the bullet speed given a firepower.default doublecalcDeltaAngle(double targetAngle, double sourceAngle)Calculates the difference between two angles, i.e. the number of degrees from a source angle to a target angle.default doublecalcGunBearing(double direction)Calculates the bearing (delta angle) between the input direction and the direction of the gun.doublecalcGunHeat(double firepower)Calculates gun heat after having fired the gun.doublecalcMaxTurnRate(double speed)Calculates the maximum turn rate for a specific speed.default doublecalcRadarBearing(double direction)Calculates the bearing (delta angle) between the input direction and the direction of the radar.voidclearEvents()Clears out any pending events in the bot's event queue immediately.default doubledirectionTo(double x, double y)Calculates the direction (angle) from the bot's coordinates to a point x,y.default doubledistanceTo(double x, double y)Calculates the distance from the bots coordinates to a point x,y.intgetArenaHeight()Height of the arena measured in units.intgetArenaWidth()Width of the arena measured in units.ColorgetBodyColor()Returns the color of the body.ColorgetBulletColor()Returns the color of the fired bullets.Collection<BulletState>getBulletStates()Current bullet states.doublegetDirection()Current driving direction of the bot in degrees.intgetEnemyCount()Number of enemies left in the round.doublegetEnergy()Current energy level.intgetEventPriority(Class<BotEvent> eventClass)Returns the event priority for a specific event class.List<BotEvent>getEvents()Returns an ordered list containing all events currently in the bot's event queue.doublegetFirepower()Returns the firepower.StringgetGameType()Game type, e.g.IGraphicsgetGraphics()Gets a graphics object that the bot can paint debug information to.ColorgetGunColor()Returns the color of the gun.doublegetGunCoolingRate()Gun cooling rate.doublegetGunDirection()Current direction of the gun in degrees.doublegetGunHeat()Current gun heat.doublegetGunTurnRate()Returns the gun turn rate in degrees per turn.doublegetMaxGunTurnRate()Returns the maximum gun turn rate in degrees per turn.intgetMaxInactivityTurns()The maximum number of inactive turns allowed the bot will become zapped by the game for being inactive.doublegetMaxRadarTurnRate()Returns the maximum radar turn rate in degrees per turn.doublegetMaxSpeed()Returns the maximum speed in units per turn.doublegetMaxTurnRate()Returns the maximum turn rate of the bot in degrees per turn.intgetMyId()Unique id of this bot, which is available when the game has started.intgetNumberOfRounds()The number of rounds in a battle.ColorgetRadarColor()Returns the color of the radar.doublegetRadarDirection()Current direction of the radar in degrees.doublegetRadarTurnRate()Returns the radar turn rate in degrees per turn.intgetRoundNumber()Current round number.ColorgetScanColor()Returns the color of the scan arc.doublegetSpeed()The current speed measured in units per turn.doublegetTargetSpeed()Returns the target speed in units per turn.Set<Integer>getTeammateIds()Returns the ids of all teammates.intgetTimeLeft()The number of microseconds left of this turn before the bot will skip the turn.ColorgetTracksColor()Returns the color of the tracks.intgetTurnNumber()Current turn number.doublegetTurnRate()Returns the turn rate of the bot in degrees per turn.intgetTurnTimeout()The turn timeout is important as the bot needs to take action by callinggo()before the turn timeout occurs.ColorgetTurretColor()Returns the color of the gun turret.StringgetVariant()The game variant, which is "Tank Royale".StringgetVersion()Game version, e.g. "1.0.0".doublegetX()Current X coordinate of the center of the bot.doublegetY()Current Y coordinate of the center of the bot.voidgo()Commits the current commands (actions), which finalizes the current turn for the bot.default doublegunBearingTo(double x, double y)Calculates the bearing (delta angle) between the current direction of the bot's gun and the direction to the point x,y.booleanisAdjustGunForBodyTurn()Checks if the gun is set to adjust for the bot turning, i.e. to turn independent of the bot's body turn.booleanisAdjustRadarForBodyTurn()Checks if the radar is set to adjust for the body turning, i.e. to turn independent of the body's turn.booleanisAdjustRadarForGunTurn()Checks if the radar is set to adjust for the gun turning, i.e. to turn independent of the gun's turn.booleanisDebuggingEnabled()Flag indicating if graphical debugging is enabled and hence ifgetGraphics()can be used for debug painting.booleanisDisabled()Specifies if the bot is disabled, i.e., when the energy is zero.booleanisStopped()Checks if the movement has been stopped.booleanisTeammate(int botId)Checks if the provided bot id is a teammate or not.default doublenormalizeAbsoluteAngle(double angle)Normalizes an angle to an absolute angle into the range [0,360[default doublenormalizeRelativeAngle(double angle)Normalizes an angle to a relative angle in the range [-180, 180).default voidonBotDeath(BotDeathEvent botDeathEvent)The event handler triggered when another bot has died.default voidonBulletFired(BulletFiredEvent bulletFiredEvent)The event handler triggered when the bot has fired a bullet.default voidonBulletHit(BulletHitBotEvent bulletHitBotEvent)The event handler triggered when the bot has hit another bot with a bullet.default voidonBulletHitBullet(BulletHitBulletEvent bulletHitBulletEvent)The event handler triggered when a bullet fired from the bot has collided with another bullet.default voidonBulletHitWall(BulletHitWallEvent bulletHitWallEvent)The event handler triggered when a bullet has hit a wall.default voidonConnected(ConnectedEvent connectedEvent)The event handler triggered when connected to the server.default voidonConnectionError(ConnectionErrorEvent connectionErrorEvent)The event handler triggered when a connection error occurs.default voidonCustomEvent(CustomEvent customEvent)The event handler triggered when some condition has been met.default voidonDeath(DeathEvent deathEvent)The event handler triggered when this bot has died.default voidonDisconnected(DisconnectedEvent disconnectedEvent)The event handler triggered when disconnected from the server.default voidonGameEnded(GameEndedEvent gameEndedEvent)The event handler triggered when a game has ended.default voidonGameStarted(GameStartedEvent gameStatedEvent)The event handler triggered when a game has started.default voidonHitBot(HitBotEvent botHitBotEvent)The event handler triggered when the bot has collided with another bot.default voidonHitByBullet(HitByBulletEvent hitByBulletEvent)The event handler triggered when the bot has been hit by a bullet.default voidonHitWall(HitWallEvent botHitWallEvent)The event handler triggered when the bot has hit a wall.default voidonRoundEnded(RoundEndedEvent roundEndedEvent)The event handler triggered when a round has ended.default voidonRoundStarted(RoundStartedEvent roundStartedEvent)The event handler triggered when a new round has started.default voidonScannedBot(ScannedBotEvent scannedBotEvent)The event handler triggered when the bot has skipped a turn.default voidonSkippedTurn(SkippedTurnEvent skippedTurnEvent)Handles the event triggered when the bot skips a turn.default voidonTeamMessage(TeamMessageEvent teamMessageEvent)The event handler triggered when the bot has received a message from a teammate.default voidonTick(TickEvent tickEvent)The event handler triggered when a game tick event occurs, i.e., when a new turn in a round has started.default voidonWonRound(WonRoundEvent wonRoundEvent)The event handler triggered when the bot has won a round.default doubleradarBearingTo(double x, double y)Calculates the bearing (delta angle) between the current direction of the bot's radar and the direction to the point x,y.booleanremoveCustomEvent(Condition condition)Removes triggering a custom event handler for a specific condition that was previously added withaddCustomEvent(dev.robocode.tankroyale.botapi.events.Condition).voidsendTeamMessage(int teammateId, Object message)Sends a message to a specific teammate.
When the message is sent, 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 byTEAM_MESSAGE_MAX_SIZE, which is set to 32768 bytes.voidsetAdjustGunForBodyTurn(boolean adjust)Sets the gun to adjust for the bot's turn when setting the gun turn rate.voidsetAdjustRadarForBodyTurn(boolean adjust)Sets the radar to adjust for the body's turn when setting the radar turn rate.voidsetAdjustRadarForGunTurn(boolean adjust)Sets the radar to adjust for the gun's turn when setting the radar turn rate.voidsetBodyColor(Color color)Sets the color of the body.voidsetBulletColor(Color color)Sets the color of the fired bullets.voidsetEventPriority(Class<BotEvent> eventClass, int priority)Changes the event priority for an event class.booleansetFire(double firepower)Sets the gun to fire in the direction that the gun is pointing with the specified firepower.voidsetFireAssist(boolean enable)Enables or disables fire assistance explicitly.voidsetGunColor(Color color)Sets the color of the gun.voidsetGunTurnRate(double gunTurnRate)Sets the turn rate of the gun, which can be positive and negative.voidsetInterruptible(boolean interruptible)Call this method 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.voidsetMaxGunTurnRate(double maxGunTurnRate)Sets the maximum turn rate which applies to turn the gun to the left or right.voidsetMaxRadarTurnRate(double maxRadarTurnRate)Sets the maximum turn rate which applies to turn the radar to the left or right.voidsetMaxSpeed(double maxSpeed)Sets the maximum speed which applies when moving forward and backward.voidsetMaxTurnRate(double maxTurnRate)Sets the maximum turn rate which applies to turn the bot to the left or right.voidsetRadarColor(Color color)Sets the color of the radar.voidsetRadarTurnRate(double gunRadarTurnRate)Sets the turn rate of the radar, which can be positive and negative.voidsetRescan()Sets the bot to rescan with the radar.voidsetResume()Sets the bot to resume movement after having been stopped, e.g. whensetStop()has been called.voidsetScanColor(Color color)Sets the color of the scan arc.voidsetStop()Sets the bot to stop all movement including turning the gun and radar.voidsetStop(boolean overwrite)Sets the bot to stop all movement including turning the gun and radar.voidsetTargetSpeed(double targetSpeed)Sets the new target speed for the bot in units per turn.voidsetTracksColor(Color color)Sets the color of the tracks.voidsetTurnRate(double turnRate)Sets the turn rate of the bot, which can be positive and negative.voidsetTurretColor(Color color)Sets the color of the gun turret.voidstart()The method used to start running the bot.
-
-
-
Field Detail
-
TEAM_MESSAGE_MAX_SIZE
static final int TEAM_MESSAGE_MAX_SIZE
The maximum size of a team message, which is 32 KB (32.786 bytes).- See Also:
- Constant Field Values
-
MAX_NUMBER_OF_TEAM_MESSAGES_PER_TURN
static final int MAX_NUMBER_OF_TEAM_MESSAGES_PER_TURN
The maximum number of team messages that can be sent per turn, which is 10 messages.- See Also:
- Constant Field Values
-
-
Method Detail
-
start
void start()
The method used to start running the bot. You should call this method from the main method or similar.Example:
public void main(String[] args) { // create myBot ... myBot.start(); }
-
go
void 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
GameStartedEventandTickEventoccurs. If thego()method is called too late, a turn timeout will occur and theSkippedTurnEventwill 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 thatgo()is called before the turn ends.The commands executed when
go()is called are set by calling the various setter methods prior to calling thego()method:setTurnRate(double),setGunTurnRate(double),setRadarTurnRate(double),setTargetSpeed(double), andsetFire(double).- See Also:
getTurnTimeout()
-
getMyId
int getMyId()
Unique id of this bot, which is available when the game has started.- Returns:
- The unique id of this bot.
-
getVariant
String getVariant()
The game variant, which is "Tank Royale".- Returns:
- The game variant of Robocode.
-
getVersion
String getVersion()
Game version, e.g. "1.0.0".- Returns:
- The game version.
-
getGameType
String getGameType()
Game type, e.g. "melee" or "1v1".First available when the game has started.
- Returns:
- The game type.
-
getArenaWidth
int getArenaWidth()
Width of the arena measured in units.First available when the game has started.
- Returns:
- The arena width measured in units
-
getArenaHeight
int getArenaHeight()
Height of the arena measured in units.First available when the game has started.
- Returns:
- The arena height measured in units
-
getNumberOfRounds
int getNumberOfRounds()
The number of rounds in a battle.First available when the game has started.
- Returns:
- The number of rounds in a battle.
-
getGunCoolingRate
double getGunCoolingRate()
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.
- Returns:
- The gun cooling rate.
- See Also:
getGunHeat()
-
getMaxInactivityTurns
int getMaxInactivityTurns()
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.
- Returns:
- The maximum number of allowed inactive turns.
-
getTurnTimeout
int getTurnTimeout()
The turn timeout is important as the bot needs to take action by callinggo()before the turn timeout occurs. As soon as theTickEventis triggered, i.e. whenonTick(dev.robocode.tankroyale.botapi.events.TickEvent)is called, you need to callgo()to take action before the turn timeout occurs. Otherwise, your bot will skip a turn and receive aonSkippedTurn(dev.robocode.tankroyale.botapi.events.SkippedTurnEvent)for each turn wherego()is called too late.First available when the game has started.
- Returns:
- The turn timeout in microseconds (1 / 1,000,000 second).
- See Also:
getTimeLeft(),go()
-
getTimeLeft
int getTimeLeft()
The number of microseconds left of this turn before the bot will skip the turn. Make sure to callgo()before the time runs out.- Returns:
- The amount of time left in microseconds.
- See Also:
getTurnTimeout(),go()
-
getRoundNumber
int getRoundNumber()
Current round number.- Returns:
- The current round number.
-
getTurnNumber
int getTurnNumber()
Current turn number.- Returns:
- The current turn number.
-
getEnemyCount
int getEnemyCount()
Number of enemies left in the round.- Returns:
- The number of enemies left in the round.
-
getEnergy
double getEnergy()
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.- Returns:
- The current energy level.
-
isDisabled
boolean 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.- Returns:
trueif the bot is disabled;falseotherwise.
-
getX
double getX()
Current X coordinate of the center of the bot.- Returns:
- The current X coordinate of the bot.
-
getY
double getY()
Current Y coordinate of the center of the bot.- Returns:
- The current Y coordinate of the bot.
-
getDirection
double getDirection()
Current driving direction of the bot in degrees.- Returns:
- The current driving direction of the bot.
-
getGunDirection
double getGunDirection()
Current direction of the gun in degrees.- Returns:
- The current gun direction of the bot.
-
getRadarDirection
double getRadarDirection()
Current direction of the radar in degrees.- Returns:
- The current radar direction of the bot.
-
getSpeed
double getSpeed()
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.- Returns:
- The current speed.
-
getGunHeat
double getGunHeat()
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.
- Returns:
- The current gun heat.
- See Also:
getGunCoolingRate()
-
getBulletStates
Collection<BulletState> getBulletStates()
Current bullet states. Keeps track of all the bullets fired by the bot, which are still active on the arena.- Returns:
- The current bullet states.
-
getEvents
List<BotEvent> getEvents()
Returns an ordered list containing all events currently in the bot's event queue. You might, for example, call this while processing another event.- Returns:
- an ordered list containing all events currently in the bot's event queue.
- See Also:
clearEvents()
-
clearEvents
void clearEvents()
Clears out any pending events in the bot's event queue immediately.- See Also:
getEvents()
-
getTurnRate
double getTurnRate()
Returns the turn rate of the bot in degrees per turn.- Returns:
- The turn rate of the bot.
- See Also:
setTurnRate(double)
-
setTurnRate
void setTurnRate(double turnRate)
Sets 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
Constants.MAX_TURN_RATEif the turn rate exceeds this value.If this property is set multiple times, the last value set before
go()counts.- Parameters:
turnRate- is the new turn rate of the bot in degrees per turn.
-
getMaxTurnRate
double getMaxTurnRate()
Returns the maximum turn rate of the bot in degrees per turn.- Returns:
- The maximum turn rate of the bot.
- See Also:
setMaxTurnRate(double)
-
setMaxTurnRate
void setMaxTurnRate(double maxTurnRate)
Sets 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 toConstants.MAX_TURN_RATE, 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 aboveConstants.MAX_TURN_RATE, the max turn rate will be set toConstants.MAX_TURN_RATE.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 after 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 callinggo(). But notice that this is only possible to execute multiple methods in parallel by using setter methods only prior to callinggo().If this method is called multiple times, the last call before
go()is executed, counts.- Parameters:
maxTurnRate- is the new maximum turn rate- See Also:
setTurnRate(double)
-
getGunTurnRate
double getGunTurnRate()
Returns the gun turn rate in degrees per turn.- Returns:
- The turn rate of the gun.
- See Also:
setGunTurnRate(double)
-
setGunTurnRate
void setGunTurnRate(double gunTurnRate)
Sets 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
Constants.MAX_GUN_TURN_RATEif the gun turn rate exceeds this value.If this property is set multiple times, the last value set before
go()counts.- Parameters:
gunTurnRate- is the new turn rate of the gun in degrees per turn.
-
getMaxGunTurnRate
double getMaxGunTurnRate()
Returns the maximum gun turn rate in degrees per turn.- Returns:
- The maximum turn rate of the gun.
- See Also:
setMaxGunTurnRate(double)
-
setMaxGunTurnRate
void setMaxGunTurnRate(double maxGunTurnRate)
Sets 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 toConstants.MAX_GUN_TURN_RATE, 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 aboveConstants.MAX_GUN_TURN_RATE, the max turn rate will be set toConstants.MAX_GUN_TURN_RATE.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 after 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 callinggo(). But notice that this is only possible to execute multiple methods in parallel by using setter methods only prior to callinggo().If this method is called multiple times, the last call before
go()is executed, counts.- Parameters:
maxGunTurnRate- is the new maximum gun turn rate- See Also:
setGunTurnRate(double)
-
getRadarTurnRate
double getRadarTurnRate()
Returns the radar turn rate in degrees per turn.- Returns:
- The turn rate of the radar.
- See Also:
setRadarTurnRate(double)
-
setRadarTurnRate
void setRadarTurnRate(double gunRadarTurnRate)
Sets 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
Constants.MAX_RADAR_TURN_RATEif the radar turn rate exceeds this value.If this property is set multiple times, the last value set before
go()counts.- Parameters:
gunRadarTurnRate- is the new turn rate of the radar in degrees per turn.
-
getMaxRadarTurnRate
double getMaxRadarTurnRate()
Returns the maximum radar turn rate in degrees per turn.- Returns:
- The maximum turn rate of the radar.
- See Also:
setMaxRadarTurnRate(double)
-
setMaxRadarTurnRate
void setMaxRadarTurnRate(double maxRadarTurnRate)
Sets 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 toConstants.MAX_RADAR_TURN_RATE, 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 aboveConstants.MAX_RADAR_TURN_RATE, the max turn rate will be set toConstants.MAX_RADAR_TURN_RATE.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 after 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 callinggo(). But notice that this is only possible to execute multiple methods in parallel by using setter methods only prior to callinggo().If this method is called multiple times, the last call before
go()is executed, counts.- Parameters:
maxRadarTurnRate- is the new maximum radar turn rate- See Also:
setRadarTurnRate(double)
-
getTargetSpeed
double getTargetSpeed()
Returns the target speed in units per turn.- Returns:
- The target speed.
- See Also:
setTargetSpeed(double)
-
setTargetSpeed
void setTargetSpeed(double targetSpeed)
Sets the new 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 that 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.
The target speed is truncated to
Constants.MAX_SPEEDif the target speed exceeds this value.If this property is set multiple times, the last value set before
go()counts.- Parameters:
targetSpeed- is the new target speed in units per turn.
-
getMaxSpeed
double getMaxSpeed()
Returns the maximum speed in units per turn.- Returns:
- The maximum speed.
- See Also:
setMaxSpeed(double)
-
setMaxSpeed
void setMaxSpeed(double maxSpeed)
Sets the maximum speed which applies when moving forward and backward. The maximum speed must be an absolute value from 0 toConstants.MAX_SPEED, both values are included. If the input speed is negative, the max speed will be cut to zero. If the input speed is aboveConstants.MAX_SPEED, the max speed will be set toConstants.MAX_SPEED.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 after 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 callinggo(). But notice that this is only possible to execute multiple methods in parallel by using setter methods only prior to callinggo().If this method is called multiple times, the last call before
go()is executed, counts.- Parameters:
maxSpeed- is the new maximum speed
-
setFire
boolean setFire(double firepower)
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
Constants.MIN_FIREPOWERand 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
Constants.MIN_FIREPOWERor higher. If the firepower is more thanConstants.MAX_FIREPOWERthe 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
getGunHeat()). 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 callinggetGunCoolingRate().The amount of energy used for firing the gun is subtracted from the bots' 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 that 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
Constants.MAX_FIREPOWERif the firepower exceeds this value.If this property is set multiple times, the last value set before go() counts.
- Parameters:
firepower- is the new firepower- Returns:
trueif the cannon can fire, i.e. if there is no gun heat;falseotherwise.- See Also:
onBulletFired(dev.robocode.tankroyale.botapi.events.BulletFiredEvent),getFirepower(),getGunHeat(),getGunCoolingRate()
-
getFirepower
double getFirepower()
Returns the firepower.- Returns:
- The firepower.
- See Also:
setFire(double)
-
setRescan
void 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.
-
setFireAssist
void setFireAssist(boolean enable)
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 towards the center of the scanned bot when all these conditions are met:
- The gun is fired (
setFire(double)andIBot.fire(double)) - The radar is scanning a bot when firing the gun (
onScannedBot(dev.robocode.tankroyale.botapi.events.ScannedBotEvent),setRescan(),IBot.rescan()) - The gun and radar are pointing in the exact the same direction. You can call
setAdjustRadarForGunTurn(false)to align the gun and radar and make sure not to turn the radar beside the gun.
The fire assistance feature is provided for backwards compatibility with the original Robocode, where robots that are not an
AdvancedRobotgot fire assistance per default as the gun and radar cannot be moved independently of each other. (TheAdvancedRobotallows the body, gun, and radar to move independent of each other).- Parameters:
enable- enables fire assistance when set totrue, and disable fire assistance otherwise.
- The gun is fired (
-
setInterruptible
void setInterruptible(boolean interruptible)
Call this method 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.Example:
public void onScannedBot(ScannedBotEvent e) { fire(1); setInterruptible(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. WithoutsetInterruptible(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. System.out.println("No bots were scanned"); }- Parameters:
interruptible-trueif the event handler should be interrupted and hence restart when a new event of the same event type occurs again;falseotherwise where the event handler will continue processing.
-
setAdjustGunForBodyTurn
void setAdjustGunForBodyTurn(boolean adjust)
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 bot's turn. When this is set, the gun will turn independent of the bot's turn.
Note: This property is additive until you reach the maximum the gun can turn
Constants.MAX_GUN_TURN_RATE. 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.Note: The gun compensating this way does count as "turning the gun".
- Parameters:
adjust-trueif the gun must adjust/compensate for the body turning;falseif the gun must turn with the body turning (default).- See Also:
setAdjustRadarForBodyTurn(boolean),setAdjustRadarForGunTurn(boolean),isAdjustGunForBodyTurn(),isAdjustRadarForBodyTurn(),isAdjustRadarForGunTurn()
-
isAdjustGunForBodyTurn
boolean isAdjustGunForBodyTurn()
Checks if the gun is set to adjust for the bot turning, i.e. to turn independent of the bot's body turn.This call returns
trueif the gun is set to turn independent of the turn of the bot's body. Otherwise,falseis returned, meaning that the gun is set to turn with the bot's body turn.- Returns:
trueif the gun is set to turn independent of the body turning;falseif the gun is set to turn with the body turning (default).- See Also:
setAdjustGunForBodyTurn(boolean),setAdjustRadarForBodyTurn(boolean),setAdjustRadarForGunTurn(boolean),isAdjustRadarForBodyTurn(),isAdjustRadarForGunTurn()
-
setAdjustRadarForBodyTurn
void setAdjustRadarForBodyTurn(boolean adjust)
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 (
Constants.MAX_RADAR_TURN_RATE). 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.Note: The radar compensating this way does count as "turning the radar".
- Parameters:
adjust-trueif the radar must adjust/compensate for the body's turn;falseif the radar must turn with the body turning (default).- See Also:
setAdjustGunForBodyTurn(boolean),setAdjustRadarForGunTurn(boolean),isAdjustGunForBodyTurn(),isAdjustRadarForBodyTurn(),isAdjustRadarForGunTurn()
-
isAdjustRadarForBodyTurn
boolean isAdjustRadarForBodyTurn()
Checks if the radar is set to adjust for the body turning, i.e. to turn independent of the body's turn.This call returns
trueif the radar is set to turn independent of the turn of the body. Otherwise,falseis returned, meaning that the radar is set to turn with the body turning.- Returns:
trueif the radar is set to turn independent of the body turning;falseif the radar is set to turn with the body turning (default).- See Also:
setAdjustGunForBodyTurn(boolean),setAdjustRadarForBodyTurn(boolean),setAdjustRadarForGunTurn(boolean),isAdjustGunForBodyTurn(),isAdjustRadarForGunTurn()
-
setAdjustRadarForGunTurn
void setAdjustRadarForGunTurn(boolean adjust)
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's turn.
Note: This property is additive until you reach the maximum the radar can turn (
Constants.MAX_RADAR_TURN_RATE). 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.
Note: This method automatically disables fire assistance when set to
true, and automatically enables fire assistance when set tofalse. This is not the case forsetAdjustGunForBodyTurn(boolean)andsetAdjustRadarForBodyTurn(boolean). Read more about fire assistance with thesetFireAssist(boolean)method.- Parameters:
adjust-trueif the radar must adjust/compensate for the gun turning;falseif the radar must turn with the gun turning (default).- See Also:
setAdjustGunForBodyTurn(boolean),setAdjustRadarForBodyTurn(boolean),isAdjustGunForBodyTurn(),isAdjustRadarForBodyTurn(),isAdjustRadarForGunTurn()
-
isAdjustRadarForGunTurn
boolean isAdjustRadarForGunTurn()
Checks if the radar is set to adjust for the gun turning, i.e. to turn independent of the gun's turn.This call returns
trueif the radar is set to turn independent of the turn of the gun. Otherwise,falseis returned, meaning that the radar is set to turn with the gun's turn.- Returns:
trueif the radar is set to turn independent of the gun turning;falseif the radar is set to turn with the gun turning (default).- See Also:
setAdjustGunForBodyTurn(boolean),setAdjustRadarForBodyTurn(boolean),setAdjustRadarForGunTurn(boolean),isAdjustGunForBodyTurn(),isAdjustRadarForBodyTurn()
-
addCustomEvent
boolean addCustomEvent(Condition condition)
Adds an event handler that will be automatically triggeredonCustomEvent(dev.robocode.tankroyale.botapi.events.CustomEvent)when theCondition.test()returnstrue.- Parameters:
condition- is the condition that must be met to trigger the custom event.- Returns:
trueif the condition was not added already;falseif the condition was already added.- See Also:
removeCustomEvent(dev.robocode.tankroyale.botapi.events.Condition)
-
removeCustomEvent
boolean removeCustomEvent(Condition condition)
Removes triggering a custom event handler for a specific condition that was previously added withaddCustomEvent(dev.robocode.tankroyale.botapi.events.Condition).- Parameters:
condition- is the condition that was previously added withaddCustomEvent(dev.robocode.tankroyale.botapi.events.Condition)- Returns:
trueif the condition was found;falseif the condition was not found.- See Also:
addCustomEvent(dev.robocode.tankroyale.botapi.events.Condition)
-
setStop
void setStop()
Sets the bot to stop all movement including turning the gun and radar. The remaining movement is saved for a call tosetResume(). 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 callinggo(). But notice that this is only possible to execute multiple methods in parallel by using setter methods only prior to callinggo().- See Also:
setResume()
-
setStop
void setStop(boolean overwrite)
Sets the bot to stop all movement including turning the gun and radar. The remaining movement is saved for a call tosetResume().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 callinggo(). But notice that this is only possible to execute multiple methods in parallel by using setter methods only prior to callinggo().- Parameters:
overwrite- is set totrueif the movement saved by a previous call to this method orsetStop()must be overridden with the current movement. When set tofalsethis method is identical tosetStop().- See Also:
setResume()
-
setResume
void setResume()
Sets the bot to resume movement after having been stopped, e.g. whensetStop()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 callinggo(). But notice that this is only possible to execute multiple methods in parallel by using setter methods only prior to callinggo().- See Also:
setStop(),setStop(boolean)
-
getTeammateIds
Set<Integer> getTeammateIds()
Returns the ids of all teammates.- Returns:
- the ids of all teammates if the bot is participating in a team or the empty set if the bot is not in a team.
- See Also:
isTeammate(int),sendTeamMessage(int, java.lang.Object)
-
isTeammate
boolean isTeammate(int botId)
Checks if the provided bot id is a teammate or not.Example:
public void onScannedBot(ScannedBotEvent event) { if (isTeammate(event.getScannedBotId()) { return; // don't do anything by leaving } fire(1); }- Parameters:
botId- is the id of the bot to check for.- Returns:
trueif the provided is id an id of a teammate;falseotherwise.- See Also:
getTeammateIds(),sendTeamMessage(int, java.lang.Object)
-
broadcastTeamMessage
void broadcastTeamMessage(Object message)
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 byTEAM_MESSAGE_MAX_SIZE, which is set to 32768 bytes. 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 limited to 10.- Parameters:
message- is the message to broadcast.- Throws:
IllegalArgumentException- if the size of the message exceeds the size limit.- See Also:
sendTeamMessage(int, java.lang.Object),getTeammateIds()
-
sendTeamMessage
void sendTeamMessage(int teammateId, Object message)Sends a message to a specific teammate.
When the message is sent, 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 byTEAM_MESSAGE_MAX_SIZE, which is set to 32768 bytes. This size is the size of the message when it is serialized into a JSON representation.
The maximum number of messages that can be sent/broadcast per turn is limited to 10.- Parameters:
teammateId- is the id of the teammate to send the message to.message- is the message to send.- Throws:
IllegalArgumentException- if the size of the message exceeds the size limit.- See Also:
broadcastTeamMessage(java.lang.Object),getTeammateIds()
-
isStopped
boolean isStopped()
Checks if the movement has been stopped.- Returns:
- true if the movement has been stopped by
setStop(); false otherwise. - See Also:
setResume(),setStop(),setStop(boolean)
-
getBodyColor
Color getBodyColor()
Returns the color of the body.- Returns:
- The color of the body or
nullif no color has been set yet, meaning that the default color will be used.
-
setBodyColor
void setBodyColor(Color color)
Sets the color of the body. Colors can (only) be changed each turn.Example:
setBodyColor(Color.RED); // the red color setBodyColor(new Color(255, 0, 0)); // also the red color- Parameters:
color- is the color of the body ornullif the bot must use the default color instead.
-
getTurretColor
Color getTurretColor()
Returns the color of the gun turret.- Returns:
- The color of the turret or
nullif no color has been set yet, meaning that the default color will be used.
-
setTurretColor
void setTurretColor(Color color)
Sets the color of the gun turret. Colors can (only) be changed each turn.Example:
setTurretColor(Color.RED); // the red color setTurretColor(new Color(255, 0, 0)); // also the red color- Parameters:
color- is the color of the gun turret ornullif the bot must use the default color instead.
-
getRadarColor
Color getRadarColor()
Returns the color of the radar.- Returns:
- The color of the radar or
nullif no color has been set yet, meaning that the default color will be used.
-
setRadarColor
void setRadarColor(Color color)
Sets the color of the radar. Colors can (only) be changed each turn.Example:
setRadarColor(Color.RED); // the red color setRadarColor(new Color(255, 0, 0)); // also the red color- Parameters:
color- is the color of the radar ornullif the bot must use the default color instead.
-
getBulletColor
Color getBulletColor()
Returns the color of the fired bullets.- Returns:
- The color of the bullets or
nullif no color has been set yet, meaning that the default color will be used.
-
setBulletColor
void setBulletColor(Color color)
Sets 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.Example:
setBulletColor(Color.RED); // the red color setBulletColor(new Color(255, 0, 0)); // also the red color- Parameters:
color- is the color of the fired bullets ornullif the bot must use the default color instead.
-
getScanColor
Color getScanColor()
Returns the color of the scan arc.- Returns:
- The color of the scan arc or
nullif no color has been set yet, meaning that the default color will be used.
-
setScanColor
void setScanColor(Color color)
Sets the color of the scan arc. Colors can (only) be changed each turn.Example:
setScanColor(Color.RED); // the red color setScanColor(new Color(255, 0, 0)); // also the red color- Parameters:
color- is the color of the scan arc ornullif the bot must use the default color instead.
-
getTracksColor
Color getTracksColor()
Returns the color of the tracks.- Returns:
- The color of the tracks or
nullif no color has been set yet, meaning that the default color will be used.
-
setTracksColor
void setTracksColor(Color color)
Sets the color of the tracks. Colors can (only) be changed each turn.Example:
setTracksColor(Color.RED); // the red color setTracksColor(new Color(255, 0, 0)); // also the red color- Parameters:
color- is the color of the tracks ornullif the bot must use the default color instead.
-
getGunColor
Color getGunColor()
Returns the color of the gun.- Returns:
- The color of the gun or
nullif no color has been set yet, meaning that the default color will be used.
-
setGunColor
void setGunColor(Color color)
Sets the color of the gun. Colors can (only) be changed each turn.Example:
setGunColor(Color.RED); // the red color setGunColor(new Color(255, 0, 0)); // also the red color- Parameters:
color- is the color of the gun ornullif the bot must use the default color instead.
-
isDebuggingEnabled
boolean isDebuggingEnabled()
Flag indicating if graphical debugging is enabled and hence ifgetGraphics()can be used for debug painting.- Returns:
trueif the graphics debugging is enabled;falseotherwise.
-
getGraphics
IGraphics getGraphics()
Gets a graphics object that the bot can paint debug information to.Example:
var g = getGraphics(); g.setStrokeColor(Color.BLUE); g.fillRectangle(50, 50, 100, 100);- Returns:
- A graphics canvas to use for painting graphical objects making debugging easier.
-
onConnected
default void onConnected(ConnectedEvent connectedEvent)
The event handler triggered when connected to the server.- Parameters:
connectedEvent- is the event details from the game.
-
onDisconnected
default void onDisconnected(DisconnectedEvent disconnectedEvent)
The event handler triggered when disconnected from the server.- Parameters:
disconnectedEvent- is the event details from the game.
-
onConnectionError
default void onConnectionError(ConnectionErrorEvent connectionErrorEvent)
The event handler triggered when a connection error occurs.- Parameters:
connectionErrorEvent- is the event details from the game.
-
onGameStarted
default void onGameStarted(GameStartedEvent gameStatedEvent)
The event handler triggered when a game has started.- Parameters:
gameStatedEvent- is the event details from the game.
-
onGameEnded
default void onGameEnded(GameEndedEvent gameEndedEvent)
The event handler triggered when a game has ended.- Parameters:
gameEndedEvent- is the event details from the game.
-
onRoundStarted
default void onRoundStarted(RoundStartedEvent roundStartedEvent)
The event handler triggered when a new round has started.- Parameters:
roundStartedEvent- is the event details from the game.
-
onRoundEnded
default void onRoundEnded(RoundEndedEvent roundEndedEvent)
The event handler triggered when a round has ended.- Parameters:
roundEndedEvent- is the event details from the game.
-
onTick
default void onTick(TickEvent tickEvent)
The event handler triggered when a game tick event occurs, i.e., when a new turn in a round has started.- Parameters:
tickEvent- is the event details from the game.
-
onBotDeath
default void onBotDeath(BotDeathEvent botDeathEvent)
The event handler triggered when another bot has died.- Parameters:
botDeathEvent- is the event details from the game.
-
onDeath
default void onDeath(DeathEvent deathEvent)
The event handler triggered when this bot has died.- Parameters:
deathEvent- is the event details from the game.
-
onHitBot
default void onHitBot(HitBotEvent botHitBotEvent)
The event handler triggered when the bot has collided with another bot.- Parameters:
botHitBotEvent- is the event details from the game.
-
onHitWall
default void onHitWall(HitWallEvent botHitWallEvent)
The event handler triggered when the bot has hit a wall.- Parameters:
botHitWallEvent- is the event details from the game.
-
onBulletFired
default void onBulletFired(BulletFiredEvent bulletFiredEvent)
The event handler triggered when the bot has fired a bullet.- Parameters:
bulletFiredEvent- is the event details from the game.
-
onHitByBullet
default void onHitByBullet(HitByBulletEvent hitByBulletEvent)
The event handler triggered when the bot has been hit by a bullet.- Parameters:
hitByBulletEvent- is the event details from the game.
-
onBulletHit
default void onBulletHit(BulletHitBotEvent bulletHitBotEvent)
The event handler triggered when the bot has hit another bot with a bullet.- Parameters:
bulletHitBotEvent- is the event details from the game.
-
onBulletHitBullet
default void onBulletHitBullet(BulletHitBulletEvent bulletHitBulletEvent)
The event handler triggered when a bullet fired from the bot has collided with another bullet.- Parameters:
bulletHitBulletEvent- is the event details from the game.
-
onBulletHitWall
default void onBulletHitWall(BulletHitWallEvent bulletHitWallEvent)
The event handler triggered when a bullet has hit a wall.- Parameters:
bulletHitWallEvent- is the event details from the game.
-
onScannedBot
default void onScannedBot(ScannedBotEvent scannedBotEvent)
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 aSkippedTurnEventfor 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.- Parameters:
scannedBotEvent- is the event details from the game.
-
onSkippedTurn
default void onSkippedTurn(SkippedTurnEvent skippedTurnEvent)
Handles the event triggered when the bot skips a turn.A turn is skipped if the bot does not send any instructions to the server (via the
go()method) before the turn timeout occurs. When this happens, the server continues using the last received set of actions, such as movement, turning rates, or firing commands.Reasons for skipped turns may include:
- Excessive processing or delays in the bot's logic, leading to a timeout.
- Failure to invoke the
go()method in the current turn. - Misaligned or unintended logic in the bot's turn-handling code.
This method can be overridden to define custom behavior for handling skipped turns, such as logging the event, debugging performance issues, or modifying the bot's logic to avoid future skips.
- Parameters:
skippedTurnEvent- An event containing details about the skipped turn.
-
onWonRound
default void onWonRound(WonRoundEvent wonRoundEvent)
The event handler triggered when the bot has won a round.- Parameters:
wonRoundEvent- is the event details from the game.
-
onCustomEvent
default void onCustomEvent(CustomEvent customEvent)
The event handler triggered when some condition has been met. Use theCondition.getName()of the condition when you need to differentiate between different types of conditions received with this event handler.- Parameters:
customEvent- is the event details from the game.
-
onTeamMessage
default void onTeamMessage(TeamMessageEvent teamMessageEvent)
The event handler triggered when the bot has received a message from a teammate.- Parameters:
teamMessageEvent- is the event details from the game.
-
calcMaxTurnRate
double calcMaxTurnRate(double speed)
Calculates the maximum turn rate for a specific speed.- Parameters:
speed- is the speed.- Returns:
- The maximum turn rate determined by the given speed.
-
calcBulletSpeed
double calcBulletSpeed(double firepower)
Calculates the bullet speed given a firepower.- Parameters:
firepower- is the firepower.- Returns:
- The bullet speed determined by the given firepower.
-
calcGunHeat
double calcGunHeat(double firepower)
Calculates gun heat after having fired the gun.- Parameters:
firepower- is the firepower used when firing the gun.- Returns:
- The gun heat produced when firing the gun with the given firepower.
-
getEventPriority
int getEventPriority(Class<BotEvent> eventClass)
Returns the event priority for a specific event class.Example:
int scannedBotEventPriority = getPriority(ScannedBotEvent.class);- Parameters:
eventClass- is the event class to get the event priority for.- Returns:
- the event priority for a specific event class.
- See Also:
DefaultEventPriority,setEventPriority(java.lang.Class<dev.robocode.tankroyale.botapi.events.BotEvent>, int)
-
setEventPriority
void setEventPriority(Class<BotEvent> eventClass, int priority)
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.Note that you should normally not need to change the event priority.
- Parameters:
eventClass- is the event class to change the event priority for.priority- is the new priority. Typically, a positive number from 1 to 150. The greater value, the higher priority.- See Also:
DefaultEventPriority,getEventPriority(java.lang.Class<dev.robocode.tankroyale.botapi.events.BotEvent>)
-
calcBearing
default double calcBearing(double direction)
Calculates the bearing (delta angle) between the input direction and the direction of this bot.bearing = calcBearing(direction) = normalizeRelativeDegrees(direction - getDirection())- Parameters:
direction- is the input direction to calculate the bearing from.- Returns:
- 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:
getDirection(),normalizeRelativeAngle(double)
-
calcGunBearing
default double calcGunBearing(double direction)
Calculates the bearing (delta angle) between the input direction and the direction of the gun.bearing = calcGunBearing(direction) = normalizeRelativeDegrees(direction - getGunDirection())- Parameters:
direction- is the input direction to calculate the bearing from.- Returns:
- 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:
getGunDirection(),normalizeRelativeAngle(double)
-
calcRadarBearing
default double calcRadarBearing(double direction)
Calculates the bearing (delta angle) between the input direction and the direction of the radar.bearing = calcRadarBearing(direction) = normalizeRelativeDegrees(direction - getRadarDirection())- Parameters:
direction- is the input direction to calculate the bearing from.- Returns:
- 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:
getRadarDirection(),normalizeRelativeAngle(double)
-
directionTo
default double directionTo(double x, double y)Calculates the direction (angle) from the bot's coordinates to a point x,y.- Parameters:
x- is the x coordinate of the point.y- is the y coordinate of the point.- Returns:
- The direction to the point x,y in the range [0,360[
-
bearingTo
default double bearingTo(double x, double y)Calculates the bearing (delta angle) between the current direction of the bot's body and the direction to the point x,y.- Parameters:
x- is the x coordinate of the point.y- is the y coordinate of the point.- Returns:
- The bearing to the point x,y in the range [-180,180[
-
gunBearingTo
default double gunBearingTo(double x, double y)Calculates the bearing (delta angle) between the current direction of the bot's gun and the direction to the point x,y.- Parameters:
x- is the x coordinate of the point.y- is the y coordinate of the point.- Returns:
- The bearing to the point x,y in the range [-180,180[
-
radarBearingTo
default double radarBearingTo(double x, double y)Calculates the bearing (delta angle) between the current direction of the bot's radar and the direction to the point x,y.- Parameters:
x- is the x coordinate of the point.y- is the y coordinate of the point.- Returns:
- The bearing to the point x,y in the range [-180,180[
-
distanceTo
default double distanceTo(double x, double y)Calculates the distance from the bots coordinates to a point x,y.- Parameters:
x- is the x coordinate of the point.y- is the y coordinate of the point.- Returns:
- The distance to the point x,y.
-
normalizeAbsoluteAngle
default double normalizeAbsoluteAngle(double angle)
Normalizes an angle to an absolute angle into the range [0,360[- Parameters:
angle- is the angle to normalize.- Returns:
- The normalized absolute angle.
-
normalizeRelativeAngle
default double normalizeRelativeAngle(double angle)
Normalizes an angle to a relative angle in the range [-180, 180).A relative angle represents the shortest angular distance between two directions. For example:
- An angle of 190° is equivalent to -170° in relative terms, as turning -170° is shorter than turning 190° to reach the same direction.
- Similarly, -190° is normalized to 170°, as turning 170° is the shorter path.
- Parameters:
angle- The angle to normalize, in degrees.- Returns:
- A normalized relative angle in the range [-180, 180).
-
calcDeltaAngle
default double calcDeltaAngle(double targetAngle, double sourceAngle)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]- Parameters:
targetAngle- is the target angle.sourceAngle- is the source angle.- Returns:
- The delta angle between a source angle and target angle.
-
-