Difference between revisions of "Bullet Flight Time"
Jump to navigation
Jump to search
RednaxelaBot (talk | contribs) m (Using <syntaxhighlight>.) |
(Improvements) |
||
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 | + | 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 | + | public static long getBulletFlightTime(double distanceToEnemy, double 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 | + | * 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 | + | * 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]] |
Revision as of 22:05, 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(...)
(orsetFireBullet
). 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).