Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.64 KB | None | 0 0
  1.    public static void goTo(String name, int[] at, int[] to)
  2.    {
  3.       // simple manhattan move
  4.  
  5.       int dx = to[0] - at[0];
  6.       int dy = to[1] - at[1];
  7.  
  8.       position(name, at[0], at[1]);
  9.  
  10.       // move along x
  11.       while (dx != 0)
  12.       {
  13.          // dx = (dx > 0) ? (dx - 1) : (dx + 1);
  14.          dx += ((dx >>> 31) << 1) - 1;
  15.          position(name, to[0] - dx, to[1] - dy);
  16.       }
  17.  
  18.       // move along y
  19.       while (dy != 0)
  20.       {
  21.          // dy = (dy > 0) ? (dy - 1) : (dy + 1);
  22.          dy += ((dy >>> 31) << 1) - 1;
  23.          position(name, to[0] - dx, to[1] - dy);
  24.       }
  25.  
  26.       position(name, to[0], to[1]);
  27.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement