# Level : Oasis not sure if bug or my mistake

#1

hi Guys i’m not sure if it’s a bug or i did a mistake so here is my code

``````# Move forward to reach the oasis,
# but move back to avoid nearby yaks.

loop:
enemy = self.findNearestEnemy()
if enemy and self.distanceTo(enemy) < 10:
# Move to the left by subtracting 10 from your X coordinate.
pass
x = self.pos.x -10
y = self.pos.y
self.moveXY(x, y)

else:
x = self.pos.x +10
y = self.pos.y
self.moveXY(x, y)
# Move to the right by addding 10 from your X coordinate.
pass
``````

Do i need to use flags too or i just to focus more
ps this is the first time getting into trouble lol so please if it’s not a bug don’t post the answer and let me figure it by my self , ty
Edit : I’m using Tharin

#2

same thing happening to me, the yak at the end gets me no matter what.

#3

Maybe we need new Glasses since ours got 5m range ?

#4

ok found the solution. just change the 10 to a 9 in the if enemy and self.distanceTo(enemy) < 10: . maybe it is just a little bug. idk

#5

it’s a bug maybe cause computer starts from 0 and they forgot to code it to start from 1 , i’m not sure , anyway ty

#6

I’m pretty confused, because my code is equivalent to yours, but the yaks don’t get me. Can you double-check how much speed you have and let me know? Also, a screenshot of the moment where the yak first gets you would help.

#7

i remember that level i had to get creative to beat it. i had the same problem with the yak hitting me.

I just rechecked it and my speed changed again i guess because it was failing. got it working again for my speed.

``````// Move forward to reach the oasis,
// but move back to avoid nearby yaks.

loop {
enemy = this.findNearest(this.findEnemies());
if (enemy && this.distanceTo(enemy) < 20) {
// Move to the left by subtracting 10 from your X coordinate.
x = this.pos.x - 4;
} else {
// Move to the right by addding 10 from your X coordinate.
x = this.pos.x + 4;
}
this.moveXY(x, this.pos.y);
}
``````

#8

Here what happend when using < 10

and it worked when used < 9

look like it count 0 as 1 as we alll now computer start from 0 and you didn’t code it to start from 1 , i’m not sure just a guess

#9

No. it’s just because everybody has different gear and different speed of movement.

#10

Maybe you’re right i mentioned in first post that I’m using Tharin as my char

#11

Yep. each hero has a speed but also they can get different boots that further changes that. so this is a pretty tricky level to make work for everybody.

#12

I used equivalent code. I made it by going slower. I had a “this.say” attached to every move.

#13

I just switched the yak timing a little bit and I think I fixed the problem; please try again with distances of 10 and let me know if you are still seeing any problems. Thanks!

#14

I could not figure out what was wrong with my code. Turns out it was just being short-sighted and trying to move too far before checking distance to yaks. I got it working with move distances of 4 and a viewing distance of 20. update: optimal seems to be move dist of 5 and view dist of 10. I’m using Anya with softened leather boots.

It’s the comments that encourage ‘rigid thinking’ with a stated fixed distance of 10. Maybe just sub in ‘a certain distance’ (experiment!) instead of specific measurements?

Also I had to add an extra ‘else’ block because the yaks eventually stop moving and so there are no enemies left to spur movement.

#15

Hmm, it’s supposed to work with `10`m movement. You say that you were trying to move too far–the yaks were getting you before you had time to run, or you ran backwards into a yak…?

#16

Speed depends on the boots. Try to change boots.
I passed this level in leather boots

#17

I did a silly hack…if I used an alert (in the JS version this.say("any message here)) at the beginning of my loop, I survived. Otherwise I died on the first movement. So I “succeeded,” but…meh.

#18

Looks like it didn’t quite work for your particular speed, so I tweaked it a bit and it should be working for that speed as well, now, too. Sorry about that!

#19

yeah 10 didn’t work. I had to switch positions ±4 works great.

#21

If you think you found a bug/possible problem, please include all info necessary to solve the issue.

Which hero?
Which equipment (only boots, ring of speed?, other speed-changing items)?

(Possibly (if extraordinary different): Your code)