Stuck on Mega-Munchkin Attacks

Ivy won’t move away from the munchkin

Blockquote
#That’s a big’un! With some clever thinking, Ivy should be able to take care of this situation single-handedly.
while True:
# Find Ivy.
Ivy = hero.findNearest(hero.findFriends())
enemy = hero.findNearest(hero.findEnemies())
# Tell Ivy to attack the enemy!
if Ivy and enemy:
hero.command(Ivy, “attack”, enemy)
# Wait, no, that doesn’t work that well. Maybe try something else?
# The munchkin is awfully slow…
if enemy.health <= 200:
hero.command(Ivy, “move”, {‘x’:19, ‘y’:13})
while True:
hero.command(Ivy, “attack”, enemy)

Hi @Psychzander and welcome to the forum! :partying_face:

Could you send us your code formated as it is described here?

Ivy won’t move away from the munchkin

# That's a big'un! With some clever thinking, Ivy should be able to take care of this situation single-handedly.
while True:
    # Find Ivy.
    Ivy = hero.findNearest(hero.findFriends())
    enemy = hero.findNearest(hero.findEnemies())
    
    # Tell Ivy to attack the enemy!
    if Ivy and enemy:
        hero.command(Ivy, "attack", enemy)
    
    # Wait, no, that doesn't work that well. Maybe try something else?
    # The munchkin is awfully slow...
    if enemy.health <= 200:
        hero.command(Ivy, "move", {'x':78, 'y':40})
        while True:
            hero.command(Ivy, "attack", enemy)

If you want to move, try to remove this loop.
Do you need any more assistance at this level?

Innor or outer loop?

The second one. ( 20 chars )

error:

The power of the archer over the munchkin in the ranged attack and the speed, so try to keep her in a safe distance so the munchkin will not reach to her. And when she is in a safe distance, then attack. Do you need any help with how to write this in code?

yes I tried telling her to move and its not working but now I have no error

Do you have any flags?

none placed though I have the purple one

tell her to move to flag.pos?

I would recommend defining distance between Ivy and the munchkin…if too close, then move away a bit, otherwise attack.

1 Like

Well, you can check the distance from the archer to the munchkin and if it is smaller than 5 command her to move to a flag (place it so she will be safe on the way and on its position) and if it is 5 or bigger, just attack the munchkin. Do you need any more assistance at this level?

I was confused by that so I changed it dedreous

1 Like

I don’t know how to work out the pos between them

That would be something like this (I used ‘friend’ instead of ‘Ivy’…doesn’t matter which one, just stick with the same one):

distance = friend.distanceTo(enemy)

Then, build an if statement to test and react accordingly.

1 Like

To find out the distance between them put something like this:

distance = Ivy.distanceTo(enemy)

Do you need any more assistance at this level?

Another error:

Try to put this

In an else for the

if distance <= 5: