diff --git a/utils.py b/utils.py index 1cb4edb..ffc5982 100644 --- a/utils.py +++ b/utils.py @@ -3,15 +3,26 @@ from __builtins__ import * world_size = get_world_size() def move_to(x, y): - while x > get_pos_x(): - move(East) - while x < get_pos_x(): - move(West) + cx = get_pos_x() + cy = get_pos_y() - while y > get_pos_y(): - move(North) - while y < get_pos_y(): - move(South) + east_steps = (x - cx) % world_size + west_steps = (cx - x) % world_size + if east_steps <= west_steps: + for _ in range(east_steps): + move(East) + else: + for _ in range(west_steps): + move(West) + + north_steps = (y - cy) % world_size + south_steps = (cy - y) % world_size + if north_steps <= south_steps: + for _ in range(north_steps): + move(North) + else: + for _ in range(south_steps): + move(South)