Загрузка данных


import time
import ctypes
import pyautogui

# Начальная скорость (0.25 сек на перемещение)
MOVE_DURATION = 0.25
USE_DRAG_AND_DROP = False
CLICK_DELAY = 0.05

try:
    ctypes.windll.shcore.SetProcessDpiAwareness(2)
except Exception:
    try:
        ctypes.windll.user32.SetProcessDpiAware()
    except Exception:
        pass

pyautogui.PAUSE = 0.02


def change_speed(delta):
    """Изменяет скорость перемещения мыши"""
    global MOVE_DURATION
    # Ограничиваем скорость от 0.05 сек (очень быстро) до 1.0 сек (очень медленно)
    MOVE_DURATION = round(max(0.05, min(1.0, MOVE_DURATION + delta)), 2)
    print(f"\n[НАСТРОЙКА] Скорость мыши: {MOVE_DURATION} сек.")


def square_to_screen_coords(square_str, roi, is_black=False):
    col_file = square_str[0]
    row_rank = square_str[1]

    col_idx = ord(col_file) - ord('a')
    row_idx = 8 - int(row_rank)

    if is_black:
        col_idx = 7 - col_idx
        row_idx = 7 - row_idx

    cell_w = roi["width"] / 8.0
    cell_h = roi["height"] / 8.0

    center_x = int(roi["left"] + (col_idx + 0.5) * cell_w)
    center_y = int(roi["top"] + (row_idx + 0.5) * cell_h)

    return center_x, center_y


def execute_move(move_uci, roi, is_black=False):
    if not move_uci or len(move_uci) < 4:
        return

    from_sq = move_uci[0:2]
    to_sq = move_uci[2:4]

    x_from, y_from = square_to_screen_coords(from_sq, roi, is_black)
    x_to, y_to = square_to_screen_coords(to_sq, roi, is_black)

    if USE_DRAG_AND_DROP:
        pyautogui.moveTo(x_from, y_from, duration=MOVE_DURATION, tween=pyautogui.easeOutQuad)
        pyautogui.mouseDown()
        time.sleep(CLICK_DELAY)
        
        pyautogui.moveTo(x_to, y_to, duration=MOVE_DURATION, tween=pyautogui.easeOutQuad)
        time.sleep(CLICK_DELAY)
        pyautogui.mouseUp()
    else:
        pyautogui.moveTo(x_from, y_from, duration=MOVE_DURATION, tween=pyautogui.easeOutQuad)
        pyautogui.click()
        time.sleep(CLICK_DELAY)

        pyautogui.moveTo(x_to, y_to, duration=MOVE_DURATION, tween=pyautogui.easeOutQuad)
        pyautogui.click()

    if len(move_uci) == 5:
        time.sleep(0.15)
        pyautogui.click(x_to, y_to)