Movement Calculation

09/27/2011 20:11 general_lolichdissdich#1
I don't want any thanks or whatsoever for this. Just throwing it out to the devs who will maybe get interested in developing another bot!
This should really only be encouraging for beginners to write new software!
You can use this without permission (no licencing).
Also it's kind of a nice and easy task if you want to do some maths again ;)
If you have questions or spotted a mistake, please tell me!

Have fun!

PHP Code:
from math import pow, sqrt

def calcposattime
(current, destination, speed, time):
    
# extract
    
currentx, currenty = current
    destinationx
, destinationy = destination
    
# errorpreventing
    
if (currentx == destinationx) and (currenty == destinationy):
        return (
0, 0)
    
# calc delta
    
deltax, deltay = currentx - destinationx, currenty - destinationy
    
# calc distance from current to destination
    
distance = sqrt(pow(deltax,2)+pow(deltay,2))
    
# distance: dis travelled in time: t with speed: v => dis = v * t
    
distance_travelled = speed * time
    
# now see how much of the final distance we made and multiply with our delta coordinates:
    
delta_travelled_x = deltax * (distance_travelled/distance)
    
delta_travelled_y = deltay * (distance_travelled/distance)
    
# and now add it to our current location
    
newx, newy = currentx - delta_travelled_x, currenty - delta_travelled_y
    
return (newx, newy)


if 
__name__ == "__main__":
    
STEPSIZE = 4
    
for x1 in range(0, 10, STEPSIZE):
        for 
y1 in range(0, 10, STEPSIZE):
            for 
x2 in range(0, 10, STEPSIZE):
                for 
y2 in range(0, 10, STEPSIZE):
                    print 
"from", x1, y1, "to", x2, y2, "=", calcposattime((x1, y1), (x2, y2), 1, 1) 
(That lower part is for testing purposes)
Python