Treasure Cave. my code is working half the time


#1

it works fine the first time i call it and go to distract the yeti but coming back it gets stuck on the trees.

def findway(x,y):
    loop:
        if self.isPathClear(self.pos, {"x": x, "y": y}):
            self.moveXY(x, y)
            
            break
        if y != self.pos.y:    
            if y > self.pos.y:
                if self.isPathClear(self.pos, {"x": self.pos.x, "y": y}):
                    self.move({"x": self.pos.x, "y": self.pos.y +1})
            elif y < self.pos.y:    
                if self.isPathClear(self.pos, {"x": self.pos.x, "y": y}):
                    self.move({"x": self.pos.x, "y": self.pos.y -1})
            else:
                pass
        if x != self.pos.x:    
            if x > self.pos.x:
                if self.isPathClear(self.pos.x, {"x": x, "y": self.pos.y }):
                    self.move({"x": self.pos.x+1, "y": self.pos.y })
            elif x < self.pos.x:    
                if self.isPathClear(self.pos, {"x": x, "y": self.pos.y }):
                    self.move({"x": self.pos.x-1, "y": self.pos.y })
            else:
                pass

#2

also what did i do wrong in the formating of this code :confounded:


#3

You were close. You are supposed to put triple backpacks (`), not ellipses. Format your code. Then we can help you.