Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Help Hunting Party

All the soldiers go for the same enemies and it runs out of time

# You can use findNearestEnemy() on your soldiers to get their nearest enemy instead of yours.
while True:
    friends = hero.findFriends()
    # Use for-loop and for each friend:
    for i in range(len(friends)):
        friend = friends[i]
        enemy = hero.findNearestEnemy()
        # If they see an enemy then command to attack.
        if enemy:
            hero.command(friend, "attack", enemy)
        # Command to move east by small steps.
        else:
            hero.command(friend, "move",{ "x":friend.pos.x + 1, "y":friend.pos.y})

hmm maybe try changing the hero.findNearestEnemy() into friend.findNearestEnemy()

Good job ChedarChease

I mean “Cheddarcheese” :grin:

1 Like

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