Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Alpine Rally Hero Too Slow! (Solved)

My code is not working as I wanted to - maybe it’s too slow or something, but I don’t know how to beat the level. I’ve tried to use the dash boots, but they didn’t help me either. What should I do?

while True:
    x = hero.pos.x + .1
    y = hero.pos.y
    enemy = hero.findNearestEnemy()
    if hero.canCast("haste", hero):
        hero.cast("haste", hero)
    if hero.isReady("reset-cooldown"):
        if not hero.canCast("haste", hero):
            if not hero.hasEffect("haste"):
                hero.resetCooldown("haste")
    if enemy:
        if enemy.type == "scout" and hero.distanceTo(enemy) < 5:
            if hero.isReady("mana-blast"):
                hero.manaBlast()
    else:
        hero.moveXY(x, y)

Thank you!

Rather that using moveXY, try using move instead. The method moveXY can be likened to a ‘fire and forget’ method…you execute the code, then all further code is ignored until the final destination is reached.

The move method allows you to take a step, execute the next line(s) of code, then start over taking the next step.

In my solution, I also defined a variable as = hero.time, as soon as haste was cast. I then used an if statement to test to see if 4 seconds had gone by…if true, resetCooldown(“haste”). I also moved in 30 meter jaunts, not a tenth (.1), but that is what worked for me.

1 Like

I listened to what you said, but I don’t understand how you make the variable hero.time. I did change moveXY to move and in 30 meters, but my code doesn’t even reach the point when the hero starts moving.
Revised Code:

while True:
    x = hero.pos.x + 30
    y = hero.pos.y
    destination = {'x':x, 'y':y}
    enemy = hero.findNearestEnemy()
    if hero.canCast("haste", hero):
        hero.cast("haste", hero)
    if hero.isReady("reset-cooldown"):
        if not hero.canCast("haste", hero):
            if not hero.hasEffect("haste"):
                hero.resetCooldown("haste")
    if enemy:
        if enemy.type == "scout" and hero.distanceTo(enemy) < 5:
            if hero.isReady("mana-blast"):
                hero.manaBlast()
    else:
        hero.move(destination)

1 Like

Oh, I skipped over the last part. You want the hero to move, no matter what, so don’t want the else clause…make it a member of the while True, instead.

In your if ‘cast haste’ statement, add a line that defines a variable as hero.time. Something as simple as:

time = hero.time

Then, replace your isReady if block with one that tests to see:
if hero.time - 4 is greater than ‘time’
then, resetCooldown
no else clause need here either.

3 Likes

Thank you! I fixed that and combined my multiple if statements into one long if _ and _ and _ statements, and pender finally went off!

2 Likes