// 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?
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.
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.
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)
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.
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)
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