Thunderhooves help me please

// Get to the oasis,
// fencing off paths with yaks on them as you go.
loop {
    enemy = this.findNearestEnemy();
    if (enemy) {
        if(enemy.pos.y < this.pos.y){
            var y = enemy.pos.y + 10;
            var x = enemy.pos.x;       
            this.buildXY("fence", x, y);                    
        }
        if(enemy.pos.y > this.pos.y){
            y = enemy.pos.y - 10;
            x = enemy.pos.x;
            this.buildXY("fence", x, y);
        }        
    }
    else {        
        var xx = this.pos.x + 10;
        var yy = this.pos.y;
        this.moveXY(xx, yy);
    }
}

So this code should work right? But my character moves too slowly for this to work. Are there any alternatives or am I doing something wrong?

1 Like

Which Character do you use? Which boots do you use?
Anya/Tharin with Leather-boots should be fast enough.

Despite some indentation problems I canā€™t see anything wrong with your code. You read the FAQ, especially the chapter about Code-presenting, right?

1 Like

I used Tharin with the reinforced boots. Every time I run the code, Tharin moves too slowly, and by the time he actually arrives to where he is supposed to build the fence the Yak is already behind him. The Yak runs around for a bit before turning around and trampling olā€™ Tharin. I then tried the leather boots and had the same problem.

1 Like

Ah, I initially couldnā€™t see the problem either, but then I loaded up your session and realized it. Change enemy.pos.y + 10, enemy.pos.x, and enemy.pos.y - 10 to use self.pos instead. You want to build the fence below you when the yak is below you, not below the yak when the yak is below you.

2 Likes

Gah! Of course! Thank you so much.

1 Like

Hey there! I am stuck on Thunderhooves as well and everything about my code seems right, when I run the code it builds the first fence then my warrior walks 10m left but then turns around as if it was going to build the fence again at the same spot (the second yak has appeared at this time and run to the oasis). Can anyone help me out a little?

Here is my code:

loop:
yak = self.findNearestEnemy()
if yak and yak.pos.y > self.pos.y:
    y = yak.pos.y - 10
    x = yak.pos.x
    self.buildXY("fence", x, y)
    pass
elif yak and yak.pos.y < self.pos.y:
    x = yak.pos.y + 10
    y = yak.pos.x
    self.buildXY("fence", x, y)
    pass
else:
    x = self.pos.x + 10
    y = self.pos.y
    self.moveXY(x, y)

and here is a screenshot of whatā€™s happening:

1 Like

You have your x and y mixed in the elif yak andā€¦

x = yak.pos.y + 10 . . . . . x = y +10
y = yak.pos.x . . . . . . . . . y = x

^ switch x= and y=

1 Like
loop {
    this.buildXY("fence", 18, 36);
    this.moveXY(38, 30);
    this.buildXY("fence", 39, 26);
    this.moveXY(61, 31);
    this.buildXY("fence", 60, 25);
    this.moveXY(70, 31);
}
// It works but it's not correct
1 Like

You just might be lucky. Every time you submit you get a new distribution of Yaks. As there are only 8 distributions, the probability to choose the right one is not that low.

You should try to solve the level in a legit way nevertheless, see it as training.

1 Like

It doesnā€™t work!!! maybe there are some difference between us

1 Like

please do not reawaken old posts please read the FAQ so we can help you to help us help you

(read the FAQ so you we can help you (in case that was to cryptic))

1 Like
Is this right ? Please tell me whats wrong with this



yak = self.findNearestEnemy()
        if yak:
            # A yak is above you if yak.pos.y is greater than your pos.y.
            # If the yak is above you, build a fence 10m below it.
            if yak.pos.y < 20 :
                x = self.pos.x
                y = self.pos.y - 5
                self.buildXY("fence", x, y)
            # If the yak is below you, build a fence 10m above it.
            pass
            elif yak.pos.y  < -10 :
                x = self.pos.x
                y = self.pos.y + 5
                self.buildXY("fence", x, y)
        else:
            # Move right 10m towards the oasis.
                x = self.pos.x + 10
                y = self.pos.y 
                self.moveXY(x, y)
1 Like

What is your problem? Help us help you; we canā€™t help you with a problem that we donā€™t know.

1 Like

You are using too much code. I went back to basics and looked at the pos code explanation and that was helpful.

1 Like

Did you not see that this post is over three months old? Please keep the dead resting!

1 Like

this is the proper code because I made it and it worked 6/8/20017

while True:
yak = hero.findNearestEnemy()
if yak:
# If yak.pos.y is greater than hero.pos.y
if yak.pos.y > hero.pos.y:

        # buildXY a "fence" 10m below the yak.
        self.buildXY("fence", yak.pos.x, yak.pos.y-10)
    # else: 
    else:
        
        # buildXY a "fence" 10m above the yak.
        self.buildXY("fence", yak.pos.x, yak.pos.y+10)
    pass
else:
    # moveXY right 10m towards the oasis.
    self.moveXY(hero.pos.x+10, hero.pos.y)
    pass

Please do not revive dead threads or post solutions. In the future, also remember to format your whole code correctly.

Here is the code i did(python)
hero.buildXY(ā€œfenceā€, 18, 38)
hero.buildXY(ā€œfenceā€, 39, 23)
hero.buildXY(ā€œfenceā€, 59, 23)
hero.moveXY(70, 32)
its that simple

Please do not revive dead threads or post solutions.

what do you mean by that?