Help in hunting Party

I really need help in hunting party, here is my code:

enemy = hero.findNearestEnemy()
while enemy:
    friends = hero.findFriends()
    
    for friend in friends:
        enemy = friend.findNearest(friend.findEnemies())
        if enemy:
            hero.command(friend, "attack", enemy)
        else:
            hero.command(friend, "move", {'x': friend.pos.x + 24, 'y':friend.pos.y})

only one person moves the rest just stays right there.

wait nvm i found it (20 chars)

ok here is the link:
CodeCombat - Coding games to learn Python and JavaScript?

use 1 else it will just run into the wall

now nobody is moving tho

the only difference in my code is that i used enemy = friend.findNearestEnemy() and that i didnt define enemy at the begening

does it work for you?

Yea it does, the probleme is defining before, it will take the one before. So the troops might be confused a little

SO ur code is this:

enemy = friend.findNearestEnemy()
while enemy:
    friends = hero.findFriends()
    
    for friend in friends:
        enemy = friend.findNearest(friend.findEnemies())
        if enemy:
            hero.command(friend, "attack", enemy)
        else:
            hero.command(friend, "move", {'x': friend.pos.x + 1, 'y':friend.pos.y})

wait no i found it

its a while true loop :wink:

you can remove that lign

so I don’t need the while true loop and the “enemy=friend.findNearestEnemy()”?

No the loop is a while true loop, the reason why it did not work is that your checking if there is an enemy. They are very far away unless you have infinite range glasses it wont work

so what do I do with the while true loop

change it to while True: and that should work fine

is there a way that the archers don’t die?
since I want the bonus.

I don’t think that this is a big deal, but you can remove the

at the top of your code.
-Grzmot

1 Like

I did (20 characters)

in my code, i dont get the bonus. But i dont know if you can summon more troops to help…

then its fine then thanks for helping :grin: :grin: :grin:

1 Like