The bane of soldiers help please


#1

I am having problems sending one soldier at a time. help would be appreciated.

while True:
    enemies = hero.findEnemies()
    enemy = hero.findNearest(enemies)
    friends = hero.findFriends()
    # Send the first soldier of the friends array towards the enemy.
    firstFriend = friends[0]
    # i in range(1, n) starts the index at the second element!
    for i in range(1, len(friends)):
        friend = friends[i]
        # Command the remaining soldiers to run away!
        hero.command(friends[3], "move", {"x": 29, "y": 34})
        hero.command(friends[9], "move", {"x": 41, "y": 55})


#2

A couple of things:

  1. You’ve defined a variable, firstFriend but don’t use it for anything. You don’t need that anyway.
# Send the first soldier of the friends array towards the enemy.
  1. You’ve not checked to see if there are any enemies and not commanded any of your friends to attack them if there are any. Just command friends[0] to do it.
# Command the remaining soldiers to run away!

Then command the rest, friends[i], to a defined retreat position. You define a single friend as a variable but never call it anywhere. You don’t need that either. You can command all of the remaining soldiers with a single line using friends[i].


#3

Thank you very much
i beat the level