Fragile Maze Level Help

Goodbye for now @Deadpool198.

Oh hello @Deadpool198 I like your new avatar - it’s awesome :wink:! I’d probably have to be on the discourse for 2 years, almost every day of the week and for a maximum of 5 hrs per day to get my own custom avatar…
I am still stuck on Brewball because my hero isn’t vectoring around the firetraps as I hoped she would be. Here is my code:

while True:
    potion = hero.findFriendlyMissiles()[0]
    firetraps = hero.findHazards()
    # Remember that a Fire Trap will trigger if you move closer than 3 meters!
    omarn = hero.findByType("potion-master")[0]
    if potion:
        dest = potion.targetPos
        # Go get the potion.
        potion = Vector.subtract(dest, hero.pos)
        potion = Vector.normalize(potion)
        potion = Vector.multiply(potion, 10)
        firetrap = hero.findNearest(firetraps)
        if hero.distanceTo(firetrap) < 10:
            firetrap = Vector.subtract(firetrap.pos, hero.pos)
            firetrap = Vector.normalize(firetrap)
            firetrap = Vector.multiply(firetrap, 10)
            potion = Vector.add(potion, firetrap)
        moveToPos = Vector.add(hero.pos, potion)
        hero.move(moveToPos)
        pass
    else:
        omarn = hero.findByType("potion-master")[0]
        if not potion:
            # Move back to Omarn.
            home = omarn.pos
            # Go get the potion.
            omarn = Vector.subtract(home, hero.pos)
            omarn = Vector.normalize(omarn)
            omarn = Vector.multiply(omarn, 10)
            firetrap = hero.findNearest(firetraps)
            if hero.distanceTo(firetrap) < 10:
                firetrap = Vector.subtract(hero.pos, firetrap.pos)
                firetrap = Vector.normalize(firetrap)
                firetrap = Vector.multiply(firetrap, 10)
                omarn = Vector.add(omarn, firetrap)
            moveToPos = Vector.add(hero.pos, omarn)
            hero.move(moveToPos)
            # Warning: isPathClear doesn't work with Hazards!
            hero.say("Hup, hup!")
        pass

Thanks, although this avatar is actually from the CodeQuest tournament, not for the forum. So do not despair! There might be another online one next year, or maybe there’ll be avatars available in the E-Sports thing Nick mentioned.
About your code:
First I would recommend keeping variable names to strictly one purpose. You used potion as the potion itself and also the potion vector. I would use a different variable like potionVec and firetrapVec. I don’t think it’s necessary, but it avoids a lot of confusion.
Next, you need to change the order of this:

Now I know that I said when you make a Vector you go from them, to you. But this is a different scenario. That’s when you want to go towards something. Here we want to stay exactly 10 metres away from the firetrap at all times. So it makes sense to have the Vector originate (or have it’s centre point at) at the firetrap’s location. Imagine you made a 10 metre Vector from the hero away from the firetrap (which you would do by subtracting the firetrap vector from the potion vector, rather than adding it.), that would mean you’re going more than 10 metres away from the fire-trap because the Vector is starting at your location. I know this is probably quite hard to understand, I’ve only started to understand it properly quite recently. Essentially, you need to subtract the Vector from you to them when you trying to avoid them (here a firetrap, but it could be an enemy as well – good for using a weak hero like pender if you want to avoid ogres).
Danny

1 Like

Ah I see now @Deadpool198

I have an issue with this because my hero just runs into the firetrap even though I switched them around:


Have I missed something or have I done everything you have said?

firetraps = hero.findHazards()
omarn = hero.findByType("potion-master")[0]
while True:
    potion = hero.findFriendlyMissiles()[0]
    firetraps = hero.findHazards()
    # Remember that a Fire Trap will trigger if you move closer than 3 meters!
    omarn = hero.findByType("potion-master")[0]
    if potion:
        dest = potion.targetPos
        # Go get the potion.
        potionVec = Vector.subtract(dest, hero.pos)
        potionVec = Vector.normalize(potionVec)
        potionVec = Vector.multiply(potionVec, 10)
        firetrap = hero.findNearest(firetraps)
        if hero.distanceTo(firetrap) < 10:
            firetrapVec = Vector.subtract(hero.pos, firetrap.pos)
            firetrapVec = Vector.normalize(firetrapVec)
            firetrapVec = Vector.multiply(firetrapVec, 10)
            potion = Vector.add(potionVec, firetrapVec)
        moveToPos = Vector.add(hero.pos, potionVec)
        hero.move(moveToPos)
        pass
    else:
        omarn = hero.findByType("potion-master")[0]
        if not potion:
            # Move back to Omarn.
            home = omarn.pos
            # Go get the potion.
            omarnVec = Vector.subtract(home, hero.pos)
            omarnVec = Vector.normalize(omarnVec)
            omarnVec = Vector.multiply(omarnVec, 10)
            firetrap = hero.findNearest(firetraps)
            if hero.distanceTo(firetrap) < 10:
                firetrap = Vector.subtract(hero.pos, firetrap.pos)
                firetrap = Vector.normalize(firetrap)
                firetrap = Vector.multiply(firetrap, 10)
                omarn = Vector.add(omarnVec, firetrap)
            moveToPos = Vector.add(hero.pos, omarnVec)
            hero.move(moveToPos)
            # Warning: isPathClear doesn't work with Hazards!
            hero.say("Hup, hup!")
        pass

Elijah :lion: :lion: :lion:

P.S. It wasn’t so hard to understand the point you were trying to get across.

Firstly, you haven’t changed

to potionVec yet.
Same with:

If you change a variable name, make sure you do it to all of them! Cmd F can help you with that. You can replace all instances of omarn for example, with omarnVec. Just make sure you don’t also change the stuff mentioning omarn himself, e.g.:

The code still won’t work yet, but the Vectoring bit will. It’s just some stuff about how you move back to Omarn… I’ll let you try and figure it out.
Danny
P.S. nice lions :wink: They truly are the king of the emoji animal kingdom.

That is true I got to the potion but I get this error saying:


As you can see, I tried to move the omarn variable closer but that didn’t work… Oh and I’m on Windows.
Handy Tip: On Windows, to edit parts of your code that need the same edit like a variable name, use Ctrl+ click to get multiple cursors!

Elijah :lion:
P.S. The first movie I remember watching was the Lion King and the real-life version is even better!

You should still have an if statement, but instead of saying if not potion, which isn’t really what you want to ask, you should say if omarn and hero.distanceTo(omarn) …Something else…

1 Like

… and I did that if not potion because my hero wouldn’t move otherwise

1 Like

Well, I changed it and it did work, so there must be something wrong. Plz post your newest code.
Danny

1 Like
firetraps = hero.findHazards()
omarn = hero.findByType("potion-master")[0]
while True:
    potion = hero.findFriendlyMissiles()[0]
    firetraps = hero.findHazards()
    # Remember that a Fire Trap will trigger if you move closer than 3 meters!
    omarn = hero.findByType("potion-master")[0]
    if potion:
        dest = potion.targetPos
        # Go get the potion.
        potionVec = Vector.subtract(dest, hero.pos)
        potionVec = Vector.normalize(potionVec)
        potionVec = Vector.multiply(potionVec, 10)
        firetrap = hero.findNearest(firetraps)
        if hero.distanceTo(firetrap) < 10:
            firetrapVec = Vector.subtract(hero.pos, firetrap.pos)
            firetrapVec = Vector.normalize(firetrapVec)
            firetrapVec = Vector.multiply(firetrapVec, 10)
            potionVec = Vector.add(potionVec, firetrapVec)
        moveToPos = Vector.add(hero.pos, potionVec)
        hero.move(moveToPos)
        pass
    else:
        omarn = hero.findByType("potion-master")[0]
        omarnDist = hero.distanceTo(omarn)
        if omarn and omarnDist > 10:
            # Move back to Omarn.
            home = omarn.pos
            # Go get the potion.
            omarnVec = Vector.subtract(home, hero.pos)
            omarnVec = Vector.normalize(omarnVec)
            omarnVec = Vector.multiply(omarnVec, 10)
            firetrap = hero.findNearest(firetraps)
            if hero.distanceTo(firetrap) < 10:
                firetrap = Vector.subtract(hero.pos, firetrap.pos)
                firetrap = Vector.normalize(omarnVec)
                firetrap = Vector.multiply(omarnVec, 10)
                omarnVec = Vector.add(omarnVec, firetrap)
            moveToPos = Vector.add(hero.pos, omarnVec)
            hero.move(moveToPos)
            # Warning: isPathClear doesn't work with Hazards!
            hero.say("Hup, hup!")
        pass
1 Like

Should you say hup hup while you’re going back to Omarn? Or only once you’ve done it (else…)

1 Like

Me just wondering why there is a topic for level help but its about another level

1 Like

@ineedhelpwithcoding this is a level that @Deadpool198 told me to complete to understand Vectors, which I need for Fragile Maze. Most of the time, I hate using concepts that I don’t understand to complete levels so I try my best to find out how to understand them.

1 Like

Yes, this topic is more about understanding Vectors, with a goal of completing Fragile maze. @FalconX11_312, have you tried putting the “hup”, “hup” in an else after the if omarn and omarnDist > 10: if statement so you only say it once you’re back at the X?

1 Like

oh ok cause i was wonder why the topic is about a certain level but then its about other levels

1 Like

I did and I tried several ways of trying to get the hero back to omarn. Once, Illia vectored around the firetraps but ended up in the top right corner of the map. At the moment, she is trying to get through to behind the peasants watching. Here is my new code:

firetraps = hero.findHazards()
omarn = hero.findByType("potion-master")[0]
while True:
    potion = hero.findFriendlyMissiles()[0]
    firetraps = hero.findHazards()
    firetrap = hero.findNearest(firetraps)
    # Remember that a Fire Trap will trigger if you move closer than 3 meters!
    omarn = hero.findByType("potion-master")[0]
    if potion:
        dest = potion.targetPos
        # Go get the potion.
        potionVec = Vector.subtract(dest, hero.pos)
        potionVec = Vector.normalize(potionVec)
        potionVec = Vector.multiply(potionVec, 10)
        distance = hero.distanceTo(firetrap)
        if distance < 10:
            firetrapVec = Vector.subtract(hero.pos, firetrap.pos)
            firetrapVec = Vector.normalize(firetrapVec)
            firetrapVec = Vector.multiply(firetrapVec, 10)
            potionVec = Vector.add(potionVec, firetrapVec)
        moveToPos = Vector.add(hero.pos, potionVec)
        hero.move(moveToPos)
        pass
    else:
        omarn = hero.findByType("potion-master")[0]
        if omarn:
            omarnDist = hero.distanceTo(omarn)
            if omarnDist > 10:
                firetraps = hero.findHazards()
                firetrap2 = hero.findNearest(firetraps)
                # Move back to Omarn.
                home = omarn.pos
                # Go get the potion.
                omarnVec = Vector.subtract(hero.pos, home)
                omarnVec = Vector.normalize(omarnVec)
                omarnVec = Vector.multiply(omarnVec, 10)
                distance = hero.distanceTo(firetrap2)
                if distance < 10:
                    firetrapVec2 = Vector.subtract(hero.pos, firetrap2.pos)
                    firetrapVec2 = Vector.normalize(firetrapVec2)
                    firetrapVec2 = Vector.multiply(firetrapVec2, 10)
                    omarnVec = Vector.add(omarnVec, firetrapVec2)
                moveToPos = Vector.add(hero.pos, omarnVec)
                hero.move(moveToPos)
                # Warning: isPathClear doesn't work with Hazards!
            else:
                hero.say("Hup, hup!")
        pass

Note that I will have made changes to the code so I will constantly be editing this post.
Thanks in advance

Elijah :lion:

1 Like

Oh it doesn’t matter I’ve solved it now. I just switched around the home and hero.pos in that particular line. Thanks for all the help @Deadpool198. I am sorry if it seems like I need a lot of help as this topic has a lot of replies. And now back to Fragile Maze

1 Like

Good job, and my pleasure.
Hopefully you’ll have a better understanding of Fragile maze now.
Danny

2 Likes

Hmm but I’m still confused as to how Vectors could be used in Fragile Maze. I have this vague idea that I would find positions with them and we would be adding to find where it is clear…

1 Like

Well, I’ll give you an idea. You can make Vectors which just represent a direction, or line. For example:

moveVec = Vector(16, 0)

This may look like you’re just making a specific position on the map into a Vector, but you can use it like a kind of line to add to your hero’s pos. For example:

moveVec = Vector(16, 0)
destination = Vector.add(hero.pos, moveVec)
if hero.isPathClear(hero.pos, desti....

You don’t have to use an if with the hero.isPathClear(), while also works.
Remember that the distance between rooms is 16 metres, so you could use that to move to the next room, if the path is clear. Once you’ve got there you can store you pos in an array. You’ll have to do much more than this to get it to properly work, but you might be able to make your hero move around with code like that.
Danny

2 Likes