Difference between revisions of "Bullet Flight Time"
Jump to navigation
Jump to search
(writing up a fresh page for bullet travel time) |
RednaxelaBot (talk | contribs) m (Using <syntaxhighlight>.) |
||
Line 3: | Line 3: | ||
== Example == | == Example == | ||
− | < | + | <syntaxhighlight> |
public static long getBulletTravelTime(double distanceToEnemy, double bulletPower) { | public static long getBulletTravelTime(double distanceToEnemy, double bulletPower) { | ||
return Math.ceil(distanceToEnemy / (20 - (3 * bulletPower))); | return Math.ceil(distanceToEnemy / (20 - (3 * bulletPower))); | ||
} | } | ||
− | </ | + | </syntaxhighlight> |
== Notes about Robocode physics == | == Notes about Robocode physics == |
Revision as of 09:22, 1 July 2010
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 travel 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 getBulletTravelTime(double distanceToEnemy, double bulletPower) {
return Math.ceil(distanceToEnemy / (20 - (3 * 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 travel 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 travel time (an element commonly used in targeting algorithms).