# You can use findNearestEnemy() on your soldiers to get their nearest enemy instead of yours.
while True:
friend = hero.findFriends()
# Use for-loop and for each friend:
for i in range(len(friend)):
# # If they see an enemy then command to attack.
friend = friend[i]
enemy = friend.findEnemies()
if enemy:
hero.command(friend, "attack", enemy)
# Command to move east by small steps.
#x = friend.pos + 5
#y = friend.pos
hero.command(friend, "move", {"x": friend.pos.x +5, "y" : friend.pos.y })
You are commanding your friend to attack an array. Instead of friend.findEnemies(), use friend.findNearestEnemy(). This way, they attack one target (the closest enemy).
# You can use findNearestEnemy() on your soldiers to get their nearest enemy instead of yours.
while True:
friend = hero.findFriends()
# Use for-loop and for each friend:
for i in range(len(friend)):
# # If they see an enemy then command to attack.
friend = friend[i]
enemy = friend.findNearestEnemy()
if enemy:
hero.command(friend, "attack", enemy)
# Command to move east by small steps.
#x = friend.pos + 5
#y = friend.pos
hero.command(friend, "move", {"x": friend.pos.x +5, "y" : friend.pos.y })
I think it may be because you are using two variables that are the same, so make sure that when using hero.findFriends(), you define it as a different variable than the individual friends.