python – Navigating the robot by finding the shortest way


I have this task where I have to make my robot find the shortest way when I enter a destination point. I’ve created some functions to assign numbers (distances) for each square and counts its way back to my robot by deleting the other options. Then the robot should only follow the numbers. Here’s also a screenshot of the map it navigates in:

Here's also a screenshot of the map it navigates in:

My code works so far, however I think I should be able to reach the same outcome by using less for loops and with a more efficient writing. I believe if I see different ways of thinking in my earlier stages, I can have a broader perspective in the future. So, any ideas on how to reach my goal with a shorter code?

    #Your Code Starts Here
"""
for x in range(0, map.width):
    for y in range(0, map.height): 
        if map.blocked(x, y):
            map.value(x, y) = -1 
        else:
            map.value(x, y) = 0
"""
def fill_around(n,m,number):
    for x in range (n-1,n+2):
        for y in range (m-1,m+2):
            if map.value(x,y) != 0:
                pass
            elif x==n+1 and y==m+1 or x==n-1 and y==m-1 or x==n-1 and y==m+1 or x==n+1 and y==m-1:
                pass
            elif map.blocked(x,y) == True:
                map.value(x,y)= -1            
            elif x==n and y==m:
                map.value(x,y)= number
            else:
                map.value(x,y)= number+1


def till_final(final_x,final_y):
final_x=9 
final_y=1
fill_around(1,1,1)
for p in range(2,17):
    for k in range(0, map.width):
        for l in range(0, map.height):
            if map.value(final_x,final_y) ==0 and map.value(k,l)==p:
                fill_around(k,l,p)

def delete_duplicates(final_x,final_y):
for k in range(0, map.width):
    for l in range(0, map.height):
        if map.value(k,l) == map.value(final_x,final_y) and k != final_x and l != final_y:
            map.value(k,l) = 0