Difference between revisions of "Bullet Flight Time"

From Robowiki
Jump to navigation Jump to search
m (Using <syntaxhighlight>.)
m (MultiplyByZer0 moved page Bullet Travel Time to Bullet Flight Time: Switch to more commonly used terminology)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
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 speed|bullet's speed]] is calculated with a formula based on its [[bullet power]], so estimating bullet travel time is very simple, but since one can never be sure how the enemy will move, it is impossible to calculate it exactly.
+
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.
  
 
== Example ==
 
== Example ==
  
<syntaxhighlight>
+
<syntaxhighlight lang="java">
public static long getBulletTravelTime(double distanceToEnemy, double bulletPower) {
+
public static long getBulletFlightTime(double distanceToEnemy, double bulletPower) {
    return Math.ceil(distanceToEnemy / (20 - (3 * bulletPower)));
+
    return Math.ceil(distanceToEnemy / robocode.Rules.getBulletSpeed(bulletPower));
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 13: Line 13:
 
In Robocode, especially among the most advanced robots, some details may be helpful to note:
 
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 travel time - 1) ticks to move before the bullet arrives.
+
* 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 <code>setFire(...)</code> (or <code>setFireBullet</code>). 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 travel time (an element commonly used in [[targeting]] algorithms).
+
* A bullet is fired from the location of a robot on the tick that it calls <code>setFire(...)</code> (or <code>setFireBullet</code>). 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).
  
 
[[Category:Terminology]]
 
[[Category:Terminology]]

Latest revision as of 22:06, 24 August 2017

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.

Example

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).