From 6e6d7f43c042f4790f676b9712431b8a91cd9fb4 Mon Sep 17 00:00:00 2001 From: Steve Dudenhoeffer Date: Fri, 23 Jan 2026 21:25:31 -0500 Subject: [PATCH] Optimize `move_to` logic in `utils.py` to minimize movement steps using modular arithmetic. --- utils.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) 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)