i’m having problems with this level. i don’t know what they are. here’s the code:

``````while True:
if hero.pos.y < 43 and hero.time < 5:
hero.move({"x":73, "y":45})
hero.move({"x":64, "y":44})
else:
fireTrap = hero.findHazards()
hero.buildXY("fire-trap", 45, 46)
pos1 = {"x":64, "y":44}
pos2 = {"x":72, "y":9}
pos3 = {"x":41, "y":13}
while fireTrap:
if hero.distanceTo(pos1) > 1:
hero.move(pos1)
elif hero.distanceTo(pos2) > 1:
hero.move(pos2)
elif hero.distanceTo(pos3) > 1:
hero.move(pos3)
coin = hero.findNearestItem()
while coin:
if coin:
hero.move(coin.pos)
hero.move({"x":41, "y":13})
hero.move({"x":72, "y":9})
``````

Hi. Could you, @dedreous, help him because I have to go to bed. Bye!

Heh…I’m already looking at it. @ActualllOLLIEpop, your hero is getting caught in a never ending (rather than endless) loop, where he is cycling between pos1 and pos2…the code never progresses beyond the move(pos2) line.

In my solution, I used a linear method, rather than loops. Not saying we can’t get your version to work, just that it might be a bit more complex than necessary. In my method, I build a trap on the X, move back behind the trees, then on to the treasure. Using the only loop, I pick up all items, then high tail it back to the starting point. This took only 7 lines of code.

If you would like to give this a try, go for it! Otherwise, we can work on your code as it is.

hi @dedreous. i’ve tried the linear method, and my hero starts by going to the place where he need to be and builds a trap, but then he goes straight to the coins here’s my code:

``````hero.move({"x":73, "y":45})
hero.move({"x":64, "y":44})
hero.buildXY("fire-trap", 45, 46)
hero.move({"x":64, "y":44})
hero.move({"x":72, "y":9})
hero.move({"x":41, "y":13})
coin = hero.findNearestItem()
while coin:
if coin:
hero.move(coin.pos)
hero.move({"x":41, "y":13})
hero.move({"x":72, "y":9})

``````

Try using moveXY rather than move. With moveXY the code waits until the hero has completed the move before running the next line of code.

thanks! (20 chars)

@jka2706, i tried it, but for some reason the trap won’t activate

If it helps, here’s my ‘dance plan’…4 moveXY statements (counting the build trap as the 1st move):

but the trap doesn’t activate does it @dedreous?

It does…it blows, just about the time I’m rounding the bottom trees, providing a distraction just long enough for me to reach the coins. The yetti does attack me, but I’m able to finish collecting all of the coins and the run back to the start…he does chase me, but it’s already too late by then, the game is over.

i managed. yay!

2 Likes