Optimize move_to logic in utils.py to minimize movement steps using modular arithmetic.

This commit is contained in:
2026-01-23 21:25:31 -05:00
parent 677f84b856
commit 6e6d7f43c0

View File

@@ -3,14 +3,25 @@ from __builtins__ import *
world_size = get_world_size()
def move_to(x, y):
while x > get_pos_x():
cx = get_pos_x()
cy = get_pos_y()
east_steps = (x - cx) % world_size
west_steps = (cx - x) % world_size
if east_steps <= west_steps:
for _ in range(east_steps):
move(East)
while x < get_pos_x():
else:
for _ in range(west_steps):
move(West)
while y > get_pos_y():
north_steps = (y - cy) % world_size
south_steps = (cy - y) % world_size
if north_steps <= south_steps:
for _ in range(north_steps):
move(North)
while y < get_pos_y():
else:
for _ in range(south_steps):
move(South)