Helpful Information
 
 
Category: Programming Languages More
moving target algorithm needed.

Hi all,
I've started to play a game called Robocode (http://www.alphaworks.ibm.com/tech/robocode).
It's a java game where you get to program your robot's AI to attack and avoid being attacked. ...
trouble is whenever I lock on to a target and fire, the target has moved on by the time my bullet gets to its location.

I know the target's initial location, its direction and speed.. the target's acceleration is 0.

I know my location, and the speed of my bullet... the bullet velocity is constant.

What I need to know is the approximate location of the target if it continues its course.

The closest thing I could find was a moving target equation for quake robots which involved three dimensional space, accelleration and quadratic equations .. (my math sucks).

any ideas?

Go to the following link and download some of the robots and look at their source code. Squigbot v2.8 just won 6 out of 6 on my machine. You might want to take a look at its targeting.

http://robocode.diverman.com/botdownloads/page=1

As you say, one solution is to calculate the function that describes the last movements of the player and then guess its next position.

This function can be calculated, AFAIK, with interpolation functions like polynomials and splines. Depending of the number of points you want to sample, the function degree rises (with 4 points, it's a polynomial of degree 3, a cubic one).

With this function you can predict the next value (it would be more or less accurate depending on the separation with the last point).

You can see an active example at

http://www.wam.umd.edu/~petersd/interp.html


The problem here is how to make it useful for 3D, because in the applet you'll see that you cannot turn. Maybe it involves having an interpolation function for each axis.

I suggest you try to make this set of functions depending on time, not on pairs of axis.

pos_X (t) = prediction interpolation function in time t
pos_Y (t) = prediction interpolation function in time t
pos_Z (t) = prediction interpolation function in time t

Hope it helps

hi,

There's a simple equation that will do the trick.

Since the aceleration is 0, and it's the second time derivative of space you have this dif. eq:

d^2S
------ == 0
dt^2

The solution is :

S = S0 + V0 * t

This solution is also valid for multidimensional spaces. So, if I understood the problem right your solution would be :

Sx = S0x + V0x * t
Sy = S0y + V0y * t

where S0x is the initial position of the target projected on the x axis. V0x is its speed on the x axis and t is the time.

If you have your speed &/| position on polar form (a magnitude and an angle) you can convert to the cartesian form (the one with the x and y axis) using this expression :

x = M sin A
y = M cos A

Where M is the magnitude and A is the angle. X and Y are the cordinates on the cartesian form.

To convert back to polar form
M = sqrt ( x^2 + y^2)
A = arctg (y/x)

I hope this helps you.

Sorry for the poor english... It's not my primary language... I must have mixed up at least one mathematical term here (they tend to differ a lot between diferent languages), but I hope someone can spot it and correct if it's wrong.

You got the mathematical terms correct from what I read.