


speed = 20
ball_detected = False

def getBallDirection():
    return 5 

def getSonar(sensor):
    return 100  
def getCompass():
    return 90  

def getGPS():
    return (50, 50)  

def move(direction, speed):
    print("Moving", direction, "at speed", speed)

for _ in range(100):  
    ball_direction = getBallDirection()
    front_distance = getSonar("front")
    left_distance = getSonar("left")
    right_distance = getSonar("right")
    compass = getCompass()
    gps_x, gps_y = getGPS()

    ball_detected = ball_direction != -1

    
    if front_distance < 20:
        if left_distance > right_distance:
            move("left", speed)
        else:
            move("right", speed)
        continue

    
    if ball_detected:
        if ball_direction < 5:
            move("left", speed)
        elif ball_direction > 5:
            move("right", speed)
        else:
            move("forward", speed)
    else:
        move("turn", speed)

    
    if gps_x < 10 or gps_x > 90 or gps_y < 10 or gps_y > 90:
        move("backward", speed)
