views:

68

answers:

2

And by adjacent, I only mean one unit left, right, up, or down. Diagonals don't count. You know the x,y grid coordinates of both positions.

Ultimately this is for AS3, but answers in pseudo code would be sufficient.

+11  A: 
abs(a.x - b.x) + abs(a.y - b.y) == 1
John Kugelman
+3  A: 

(a.x - b.x) ^ 2 + (a.y - b.y) ^ 2 = 1

Michael Bray
Squaring the values is completely redundant (1 ^ 2 = 1)
Alex Barrett
not true... it's purposed is to correct the sign when a.x - b.x = -1 or a.y - b.y = -1 (just as 'abs' does in the accepted answer)
Michael Bray
Squaring is more expensive though I'd think.
Matthew Scharley
I agree... which is why I voted up the other answer. :)
Michael Bray