Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
January 11th, 2002, 11:58 PM
 Jonathon
T-Shirt Tragic

Join Date: Mar 2001
Location: Melbourne, Australia
Posts: 886
Time spent in forums: 1 Week 4 Days 6 h 53 m 39 sec
Reputation Power: 320
moving target algorithm needed.

Hi all,
I've started to play a game called 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?

#2
January 12th, 2002, 11:07 PM
 dcaillouet
Big Endian

Join Date: May 2001
Location: Fly-over country
Posts: 1,172
Time spent in forums: 16 h 29 m 5 sec
Reputation Power: 29
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.

#3
January 15th, 2002, 04:22 AM
 Thrasher
Canta como rafaé

Join Date: Feb 2001
Location: Barcelona
Posts: 74
Time spent in forums: < 1 sec
Reputation Power: 13
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
__________________
Thrasher

'Y se ahogaron los dooos
No eran duros pa pagar, cuñaaoo !!'
El vagamundo - El risitas y su cuñao

#4
February 1st, 2002, 01:18 AM
 gralves
Junior Member

Join Date: Feb 2002
Location: Sao Paulo - SP - BRAZIL
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
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.
JimmyGosling agrees!

#5
February 2nd, 2002, 01:42 AM
 Michael_Bray
Contributing User

Join Date: Sep 2000
Location: Sydney, NSW, Australia
Posts: 40
Time spent in forums: < 1 sec
Reputation Power: 14
You got the mathematical terms correct from what I read.
__________________
Cheers,
Michael Bray

 Viewing: Dev Shed Forums > Programming Languages - More > Software Design > moving target algorithm needed.