0

I keep having this problem where I'm trying to find a path to a location using items that are stored in a dictionary, I'm trying to make it so that I can estimate how long it will take to get to the location without actually doing anything to determine the best route. The problem is that when I set a throwaway value to be the current location to then find the distance by altering it in the right direction it changes the value in the dictionary. Is there any way to stop this?

def routeplan(guy):

    pos = (guys.get(guy)).get('currentloc')
    dest = (guys.get(guy)).get('targetloc')

    score = 0
    square = pos
    while square != dest:
        if square[0] < dest[0]:
            square[0] += 1
            score += 1
        elif square[0] > dest[0]:
            square[0] -= 1
            score += 1
        if square[1] < dest[1]:
            square[1] += 1
            score += 1
        elif square[1] > dest[1]:
            square[1] -= 1
            score += 1
    print(pos)

0 Answers0