1 Like

Goal is get to the Oasis. You’ll be building fences to block the yaks.

1 Like

Ask a specific question and you might get an answer. Post some code you have tried and we might be able to point you in the right direction.

1 Like

We had some issues with Thunderhooves earlier today as well. Nothing in the code lessons so far really teach you how to “move on” after you solve a problem.

First step is to fill out the skeleton code that the quest gives you to detect a Yak and build a fence in the correct location. The question then is how do you stop your guy from just continually making a fence in that once spot. There are a couple of ways to do it, but here is one suggestion…

As well as checking the Yak’s Y value relative to your own, you may want to compare your X position to the Yak. If the Yak is in front of you, do the fence building routine - then you can ignore the Yak if it is behind you. After you build a fence, move to a slightly greater value of X than the Yak.

It seems like a lesson or two to teach the concept of having a state check may be beneficial before this level.

1 Like

I guess what we had intended was something more similar to the previous level:

``````move to self.pos.x  + 10, self.pos.y
if there's an enemy
if it's above you
build a fence below it
else
build a fence above it``````

So the movement happens every time like it was happening in Sarven Road.

Is there some way we could have made it easier to figure out the easy way to do it there?

1 Like

Maybe in the skeleton code give them the movement right and an initial “is Yak in front of you” check and let them add the if above or if below checks and build fences inside of that?

That also gives another example of how to compare positions…

1 Like

Putting my pre-existing programming experience aside this level could use more explanation on coordinates. Beginners won’t easily “translate” above/beyond into coordinates comparison without hints.

3 Likes

Thanks, I’ve made a couple clarifications in the sample code.

Let me check the analytics on the level completion rate after it’s been out for a while to see if we need to make it easier by giving players the 10m right movement. I’d love it if players would be doing that part from scratch by this level, but perhaps it’s still too much.

1 Like

Here is the code with proper indentation

`````` loop:
enemy = self.findNearestEnemy()
if enemy:
# If the yak is above you, build a fence 10m below it.
if self.distanceTo(enemy) < 20:
x = enemy.pos.x
y = enemy.pos.y - 10
self.buildXY("fence", x, y)
# If the yak is below you, build a fence 10m above it.
if self.distanceTo(enemy) > 10:
x = enemy.pos.x
y = enemy.pos.y + 10
self.buildXY("fence", x, y)
pass
else:
# Move right 10m towards the oasis.
pass
x = self.pos.x + 10
y = self.pos.y
self.moveXY(x, y)
``````
1 Like

I use JavaScript, but the concepts should be the same. Instead saying that if the distance to the enemy was less than 20, then build a fence, I compared my y coordinate to the enemy’s y coordinate. For example, I said that if it’s y coordinate was greater than mine (it would be above me), then build a fence at the same x coordinate as it, but at a y coordinate that was 10 less than its y coordinate. I made 2 variables (ex and ey), that was the coordinates of the enemy. Hope this helps.

1 Like

Thanks alot abducktion! I got it working.

1 Like

Hello,

This level was frustrating for two reasons. No explanation to how to find - let alone use the coordinates of the enemy yacks. And no explanation on the “pass” command.

This one should be split into two or three different levels.

While it is possible to get this level to work using some other method - the below answer is the correct one as it uses the yacks and your current position…

``````loop:
enemy = self.findNearestEnemy()
if enemy:
# Define the yack's x and y position in a variable (yackx/yacky). And your current x and y position in a variable (myposx/myposy).
pos = enemy.pos
yackx = pos.x
yacky = pos.y
mypos = self.pos
myposx = mypos.x
myposy = mypos.y
# Now compare the yacks Y postion to my Y positon. If it is greater than... create the fence -10 blocks  below the yack.
if yacky > myposy:
self.buildXY ("fence", yackx, yacky - 10)
pass
# Now compare the yacks Y postion to my Y positon if it is less than... create the fence + 10 blocks above the yack.
elif yacky < myposy:
self.buildXY ("fence", yackx, yacky + 10)
pass
else:
# Move right towards the oasis.
pos = self.pos
xa = pos.x
ya = pos.y
self.moveXY(xa + 10, ya)``````
2 Likes

This has been explained numerous times in previous levels… finding enemies and accessing the .pos property.

1 Like

What level(s) was that?

1 Like

I don’t recall specifically which one is the first to introduce you to the .pos property but copper meadows for one uses it in conjunction with flag objects

1 Like

I also need help with this level when I run it my char just stands there

``````// Get to the oasis,
// fencing off paths with yaks on them as you go.
loop {
enemy = this.findNearestEnemy();
if (enemy) {
// A yak is above you if it's y is greater than your y.
// If the yak is above you, build a fence 10m below it.

if(enemy.pos.y < this.pos.y){
var y = enemy.pos.y + 10;
var x = enemy.pos.x;
this.buildXY("fence", x, y);

}
else if(enemy.pos.y > this.pos.y){
y = enemy.pos.y - 10;
x = enemy.pos.x;
this.buildXY("fence", x, y);
}
else {

x = this.pos.x + 10;
y = this.pos.y;
this.moveXY(x, y);

}
}
}
``````
1 Like

It is correct.

You have ‘var x’ and ‘var y’ as the enemy X and Y POS variables, as WELL as your own X and Y POS variables.

`````` var y = enemy.pos.y + 10;
var x = enemy.pos.x;
``````
``````        y = enemy.pos.y - 10;
x = enemy.pos.x;
``````
``````        x = this.pos.x + 10;
y = this.pos.y;
``````

Maybe define your enemy POS variables as different variable names than your own?

I just shortcutted the entire variable definition, via sotonin’s suggestion.

eg:

``````       if yak.pos.y > self.pos.y:
self.buildXY("fence", yak.pos.x, yak.pos.y-10)
``````
1 Like

I fixed the problem but it still is not working help pls

here is my code now

``````// Get to the oasis,
// fencing off paths with yaks on them as you go.
loop {
enemy = this.findNearestEnemy();
if (enemy) {
// A yak is above you if it's y is greater than your y.
// If the yak is above you, build a fence 10m below it.

if(enemy.pos.y < this.pos.y){
var y = enemy.pos.y + 10;
var x = enemy.pos.x;
this.buildXY("fence", x, y);

}
else 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);

}
}
}
``````
1 Like

Your problem is that you check the following:

``````IF there is an enemy THEN
IF the enemy is above me THEN
//do something
ELSE IF the enemy is below me THEN
//do something
ELSE (that is the enemy is neither above nor below me) DO
//move
``````

What you actually want is

``````IF there is an enemy THEN
//check if enemy is above or below
ELSE (that is there is no enemy visible) DO
//move
``````
2 Likes

I changed that to but my code still does not work
here is my code

``````// Get to the oasis,
// fencing off paths with yaks on them as you go.
loop {
enemy = this.findNearestEnemy();
if (enemy) {
// A yak is above you if it's y is greater than your y.
// If the yak is above you, build a fence 10m below it.

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);

}
}
}
``````
1 Like