Bullet Flight Time

From Robowiki
(Redirected from Bullet Travel Time)
Jump to navigation Jump to search

The number of ticks that will pass between the time a bot fires a bullet and the time that the bullet hits (or would hit) the enemy. A bullet's speed is calculated with a formula based on its bullet power, so estimating bullet flight time is very simple, but since one can never be sure how the enemy will move, it is impossible to calculate it exactly.


public static long getBulletFlightTime(double distanceToEnemy, double bulletPower) {
    return Math.ceil(distanceToEnemy / robocode.Rules.getBulletSpeed(bulletPower));

Notes about Robocode physics

In Robocode, especially among the most advanced robots, some details may be helpful to note:

  • Bullet collision detection happens after bullets advance but before robots advance; in effect, this means that the enemy bot has (bullet flight time - 1) ticks to move before the bullet arrives.
  • A bullet is fired from the location of a robot on the tick that it calls setFire(...) (or setFireBullet). Any calls to turn the gun on that tick take place after the bullet is fired. This means when you are aiming, the most accurate location to consider as the source of your bullet is your location next tick, which could affect bullet flight time (an element commonly used in targeting algorithms).