Inverted locations:
Left: 0
Top: 0
Right: map width
Bottom: n
Will be refereed to as y_n.
Up and Down refer to the size of the unit according to DatEdit.
Function previous (c):
Center y_n around the location that was centered around the unit c cycles ago.
Select the y_n with largest value n that contains the unit.
Return the n of that location.
That is a function that you can actually call in starcraft to gather information. Now the question is how do those functions work numerically. The answer is:
Input in this is the number of pixels the unit has moved since c cycles ago. It's actually a signed integer, with negative values being up and positive value being down.
Code
Function X (up, down, input):
a = up + input
b = down - input
if (b > a)
output = a * 2
if (down > up)
output = output + 1
else
output = b * 2
return output
a = up + input
b = down - input
if (b > a)
output = a * 2
if (down > up)
output = output + 1
else
output = b * 2
return output
Using previous(1), previous(2) and the value of previous(1) the one cycle ago, Lethal was able to gather the three values necessary to do his map. I use the same data.
a is return value of previous(1)
b is the return value of previous(2)
c is the return value of previous(1) last cycle
Now I convert it into a numerical relation:
Alpha is the signed pixels that the unit has moved since last cycle.
Beta is the signed pixels that the unit has moved since two cycles ago.
Beta - alpha is the distance the unit has moved between last cycle and two cycles ago.
Code
Function Y (up, down, alpha, beta)
a = X(up, down, alpha)
b = X(up down, beta)
c = X(up, down, beta - alpha)
return (a, b, c)
a = X(up, down, alpha)
b = X(up down, beta)
c = X(up, down, beta - alpha)
return (a, b, c)
Now I can finally state the problem. Given up, down, a, b and c, we want to find alpha, which will give us the magnitude of movement. To see if the direction has been changed we need to find beta, and then if alpha is positive, the unit has changed direction if beta is less than alpha, and if alpha is negative, the unit has changed direction if beta is greater than alpha.
Now if X was a one to one function this would be easy. We would just call inverse_X on a and b. However it isn't. So what we do is we call inverse_X on a, b and c to get a1, a2, b1, b2, c1, c2. Then we brute force it:
Code
if(b1 - a1 == c1) A = a1, B = B1
ifb1 - a1 == c2) A = a1, B = B1
if(b1 - a2 == c1) A = a2, B = B1
if(b1 - a2 == c2) A = a2, B = B1
if(b2 - a1 == c1) A = a1, B = B2
if(b2 - a1 == c2) A = a1, B = B2
if(b2 - a2 == c1) A = a2, B = B2
if(b2 - a2 == c2) A = a2, B = B2
ifb1 - a1 == c2) A = a1, B = B1
if(b1 - a2 == c1) A = a2, B = B1
if(b1 - a2 == c2) A = a2, B = B1
if(b2 - a1 == c1) A = a1, B = B2
if(b2 - a1 == c2) A = a1, B = B2
if(b2 - a2 == c1) A = a2, B = B2
if(b2 - a2 == c2) A = a2, B = B2
Now lets take a unit, with up 14 down 10. It's location one tick ago was 4 pixels upwards from its current location. It's location two ticks ago was 8 pixels upwards from its current location. -8 - -4 = -4.
alpha = -4
beta = -8
a = X(-4) = 20
b = X(-8) = 12
c = X(-8 - -4) = 20
If you invert those you get:
Code
a1 = -4
a2 = 0
b1 = -8
b2 = 4
c1 = -4
c2 = 0
-8 - -4 = -4 TRUE
-8 - -4 = 0 FALSE (-4)
-8 - 0 = -4 FALSE (-8)
-8 - 0 = 0 FALSE (-8)
4 - -4 = -4 FALSE (8)
4 - -4 = 0 FALSE (8)
4 - 0 = -4 FALSE (4)
4 - 0 = 0 FALSE (4)
a2 = 0
b1 = -8
b2 = 4
c1 = -4
c2 = 0
-8 - -4 = -4 TRUE
-8 - -4 = 0 FALSE (-4)
-8 - 0 = -4 FALSE (-8)
-8 - 0 = 0 FALSE (-8)
4 - -4 = -4 FALSE (8)
4 - -4 = 0 FALSE (8)
4 - 0 = -4 FALSE (4)
4 - 0 = 0 FALSE (4)
Because only the first one is true, we know from the values of a, b and c, the values of alpha and beta. We can then use alpha and beta to detect the pixel coordinates.
Now the question is, will there always only be one true combination? If the answer is yes than we can build a generalized pixel perfect coordinate detection system.
EDIT:
Code
Function Inverse_X (input)
if(Is_Odd(input))
a = input / 2
a = a - up
return a
else
a = input / 2
b = input / 2
a = down - a
b = b - up
return (a, b)
if(Is_Odd(input))
a = input / 2
a = a - up
return a
else
a = input / 2
b = input / 2
a = down - a
b = b - up
return (a, b)
Post has been edited 2 time(s), last time on Nov 13 2009, 12:14 am by scwizard.
None.