Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void goTo(String name, int[] at, int[] to)
- {
- // simple manhattan move
- int dx = to[0] - at[0];
- int dy = to[1] - at[1];
- position(name, at[0], at[1]);
- // move along x
- while (dx != 0)
- {
- // dx = (dx > 0) ? (dx - 1) : (dx + 1);
- dx += ((dx >>> 31) << 1) - 1;
- position(name, to[0] - dx, to[1] - dy);
- }
- // move along y
- while (dy != 0)
- {
- // dy = (dy > 0) ? (dy - 1) : (dy + 1);
- dy += ((dy >>> 31) << 1) - 1;
- position(name, to[0] - dx, to[1] - dy);
- }
- position(name, to[0], to[1]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement