I need help with "Wild Horses" Python version

I’m pretty much clueless as to where to start here. Here’s what I have (I just started coding):

 # horse = ?
    horse = self.findFriends()
    if horse:
        self.pos = horse.pos
        x1 = horse.pos.x - 7 
        x2 = horse.pos.x + 7
        y = horse.pos.y
        
        if x1 >= 1:
            self.moveXY(x,horse.pos.y)
            # Move to the horse's y position but use x1 for the x position.
            
        elif x2 <= 79:
            # Move to the horse's y position but use x2 for the x position.
            
        distance = self.distanceTo(horse)
        if distance <= 10:
            self.say("Whoa")
            self.moveXY(27, 54)
            self.moveXY(43, 21)
            # Move to the red x to return the horse to the farm.
            
            # Move back out into the pasture to begin looking for the next horse.

Hi, I made a small edit to your post to show the code block correctly (you can find details about that in the FAQ).

Looking a the code - when you do findFriends() this will give you an array of horses (in this case) - but you need to find just one, maybe the the nearest?

For the first moveXY the comment says to use x1 - but you seem to be using x. You can then follow the comment for the elif.

Does that get you a bit closer? Give it a go, and let us know how you get on.

1 Like

Thanks Matt, that helped :slight_smile:

it doesn’t work for me it says ‘pos’ was null. use a null check before accessing properties

Quoting Feinty:
http://discourse.codecombat.com/t/clash-of-clones-is-it-possible-to-win/2977/22?u=j_f_b_m