Level : Oasis not sure if bug or my mistake

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

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

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

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

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

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.

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

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

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

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

2 Likes

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

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.

2 Likes

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

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!

2 Likes

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.

Hmm, it’s supposed to work with 10m 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…?

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

1 Like

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.

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!

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

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)