Basin Stampede Help


#1

What is wrong with my code?

loop:
enemy = self.findNearest(self.findEnemies())
if enemy and self.distanceTo(enemy) < 10:

     x = self.pos.x
     y = self.pos.y - 10
     self.moveXY(x, y)
 else:
     pass
     x = self.pos.x
     y = self.pos.y + 10
     self.moveXY(x, y)

Please help.


#2

It looks like you’re using the wrong code to try and solve this level.

In Basin Stampede you want to check whether the Yaks are above or below you, and move accordingly. Not move up if they are close, down if they are far.


#3

You may also consider increasing your X value…


#4

whats wrong with this code?

Keep moving right, but adjust up and down as you go.

while True:
    enemy = hero.findNearestEnemy()
    xPos = hero.pos.x + 5
    yPos = 17
    if enemy:
        # Adjust y up or down to get away from yaks.
        if enemy.pos.y > hero.pos.y:
            # If the Yak is above you, subtract 3 from yPos.
            hero.pos.y - 3
            pass
        elif enemy.pos.y < hero.pos.y:
            # If the Yak is below you, add 3 to yPos.
            hero.pos.y + 3
            pass
    hero.moveXY(xPos, yPos)

#5

The problem is in these lines:

You’ve changed your pos, not yPos.
Hope this helps!


#6

that was a great hint but the code doesn’t work still this is my code.

# Keep moving right, but adjust up and down as you go.

while True:
    enemy = hero.findNearestEnemy()
    xPos = hero.pos.x + 5
    yPos = 17
    if enemy:
        # Adjust y up or down to get away from yaks.
        if enemy.pos.y > hero.pos.y:
            # If the Yak is above you, subtract 3 from yPos.
            yPos - 3
            pass
        elif enemy.pos.y < hero.pos.y:
            # If the Yak is below you, add 3 to yPos.
            yPos + 3
            pass
    hero.moveXY(xPos, yPos)

the problem of the code is in the running corner it only lights up the hero.move(xpos, ypos)


#7

Try this, instead of just using the if enemy: conditional, try putting if enemy and hero.distanceTo(enemy) < 12:. That way, when the yaks get closer than the given distance, it triggers the while True loop to iterate through the if conditional at a specific event. Also, the code isn’t using the reassigned values of yPos in the conditional statements. However, if you change yPos - 3 and yPos + 3 to hero.moveXY(xPos, yPos - 3) and hero.moveXY(xPos, yPos + 3) respectively, the hero then moves properly.

You may have to adjust the numbers a little bit (I did) but with these changes you should see the correct movement of the hero.


#8

Or you could just say: yPos -= 3 and yPos += 3 and that reassigns the variable yPos, that’s what i used and it’s really simple.


#9

Thanks for the amazing help guys I got the level finished
well because I got rocked to the oasis…