Help with treasured in ice(glacier level) PLS HELP!

while True:
    item = hero.findNearestItem()
    if hero.isPathClear(hero.pos, item.pos):
        hero.move(item.pos)
    else:
        

the problem is that i don’t know what to put in the else section to work :worried:

pls anyone help(20 chars)? :sob:

i havent completed this level but please format your code properly by pressing the </> sign its a simple but efficent way

while True:
item = hero.findNearestItem()
if hero.isPathClear(hero.pos, item.pos):
hero.move(item.pos)
else:

i’ve formated his code

I need help now pls(20 chars)

No you haven’t :smile:, the whole point of formatting is to include the spaces.
So this:

while True:
    item = hero.findNearestItem()
    if hero.isPathClear(hero.pos, item.pos):
        hero.move(item.pos)
    else:

This level is very very hard. Have you completed Fragile maze yet? The level is very similar and you can’t have passed Fragile maze with such short code. If you haven’t I would do that one first.
Danny

this is new code(formatted) and added more code:


distance = 16
move = Vector(distance, 0)
direction = Vector.add(move, hero.pos)
while True:
    item = hero.findNearestItem()
    
    while not (hero.isPathClear(hero.pos, item)):
        move = Vector.rotate(move, Math.PI / 2)
        direction = Vector.add(move, hero.pos)
        if hero.time < 36.6:
            hero.blink(item.pos)
            hero.moveXY(35, 18)
    hero.moveXY(direction.x, direction.y)
    move = Vector.rotate(move, -Math.PI / 2)
    direction = Vector.add(move, hero.pos)

i have with this code:


distance = 16
move = Vector(distance, 0)
direction = Vector.add(move, hero.pos)
while True:
    while not (hero.isPathClear(hero.pos, direction)):
        move = Vector.rotate(move, Math.PI / 2)
        direction = Vector.add(move, hero.pos)
    hero.moveXY(direction.x, direction.y)
    move = Vector.rotate(move, -Math.PI / 2)
    direction = Vector.add(move, hero.pos)

Sorry for not replying for so long.
This code is a great improvement.
What you need to do now is to make some kind of visited = [] array that will store the places you have visited. Then when you’re deciding whether to go somewhere, you can use a for loop to check if you’ve been there before.
Danny

not sure how to do that in which code

Did you not use a visited array for fragile maze? Perhaps you used another method :grin:. Using swap maybe? (If you did, really don’t worry about it, tbh the first time I did fragile maze I could not do it, so I kind of cheated. It’s sometimes a good plan to move on past these levels and come back later to have another go. I did that quite recently and can now do all the levels I use to find really hard.)
But if you want to learn how to use a visited array, think about how you can .append() stuff to an array, like visited.append(Vector(hero.pos.x, hero.pos.y)) and then you could use for loops to loop through visited and if the position you are about to move to is the same as one of the items in the visited array you could turn a variable like taken or already_visited to True so you don’t go there.
Danny

2 Likes

no, I used this code:


distance = 16
move = Vector(distance, 0)
direction = Vector.add(move, hero.pos)
while True:
    while not (hero.isPathClear(hero.pos, direction)):
        move = Vector.rotate(move, Math.PI / 2)
        direction = Vector.add(move, hero.pos)
        hero.say(direction)
    hero.moveXY(direction.x, direction.y)
    move = Vector.rotate(move, -Math.PI / 2)
    direction = Vector.add(move, hero.pos)

remember we have to get the treasure too.

the only level left for me is treasured in ice and capture the flag. and i’m also having trouble with capture the flag.

Okay, fair enough :grin:.
Umm, I really would recommend using an array of visited as I said above. Also, because you need to escape the maze, a visited array is really really helpful. Why? If you have a list of all the coordinates you used to get there, you can visited.reverse(), which reverses the order of the coordinates, meaning you can escape the maze.
Your code is good because it does use Vectors(). All you need to do now is implement a feature where, before you move, you use a for loop to loop through the visited array to check if your next location (not your current one) has already been visited. If it has, you have to rotate the vector again, and check again. If not, you move there and .append() it to the visited array.
I hope this helps, sorry for the slow reply,
Danny

1 Like

it’s ok i solved it thanks :sunglasses: :slightly_smiling_face: :grinning:

2 Likes

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.