Predictive targeting

Simon ParkerPublished on May , 2002

All successful targeting and shooting of enemy robots requires an algorithm to fire
bullets at the place where you predict that an enemy robot will be at a future point in time. This algorithm can be used for linear, circular, and oscillating predictive targeting. And if you have a function that returns the position of the enemy at a future point in time, you can use the algorithm to calculate the impact point, the firing angle, the impact position, and the impact time.

This algorithm implements the secant method to numerically solve the impact time. Once this impact time is known, our predictive function obtains the impact position. Then we fire at that position.

The Intercept class shown in Listing 1 assumes that the robot is traveling in a straight line from its current position at its current velocity.

The great thing about the Intercept class is that it can be easily reused to
calculate the firing angle for circular motion. To do this, write a
CircularIntercept class that inherits from the Intercept
class, and overwrite the getEstimatedPosition() method.
Listing 2 shows the code for the CircularIntercept class:

Listing 3 shows an example of using the Intercept class. It assumes that we calculated the current position, heading, and velocity of the target, as well as the power of the bullet that we will be firing.

This firing strategy has proven very successful in both of my robots (JollyNinja and MadHatter). Encapsulating the intercept in its own class and subclassing it for different prediction algorithms allows me to usually hit other robots more than they hit me.