# Help: Stuck on Library Tactician

I can’t seem to finish this level. Each time it says “try hero.findNearest( ).” Here is my code.

# Soldiers spread out in a circle and defend.

def commandSoldier(soldier, soldierIndex, numSoldiers):
angle = Math.PI * 2 * soldierIndex / numSoldiers
defendPos = {“x”: 41, “y”: 40}
defendPos.x += 10 * Math.cos(angle)
defendPos.y += 10 * Math.sin(angle)
hero.command(soldier, “defend”, defendPos);

# This function returns something! When you call the function, you will get some value back.

def findStrongestTarget():
mostHealth = 0
bestTarget = None
enemies = hero.findEnemies()
enemyIndex = 0
# Figure out which enemy has the most health, and set bestTarget to be that enemy.
while len(enemies) > enemyIndex:
enemy = enemies[enemyIndex]
if enemy:
enemyIndex += 1
if enemy.health > mostHealth:
mostHealth = enemy.health
bestTarget = enemy
# Only focus archers’ fire if there is a big ogre.
if bestTarget and bestTarget.health > 15:
return bestTarget
else:
return None

# If the strongestTarget has more than 15 health, attack that target. Otherwise, attack the nearest target.

def commandArcher(archer):
nearest = archer.findNearest(archer.findEnemies())
if archerTarget:
hero.command(archer, “attack”, archerTarget)
elif nearest:
hero.command(archer, “attack”, nearest)

archerTarget = None

while True:
# If archerTarget is dead or doesn’t exist, find a new one.
if not archerTarget or archerTarget.health <= 0:
# Set archerTarget to be the target that is returned by findStrongestTarget()
archerTarget = findStrongestTarget()

``````friends = hero.findFriends()
soldiers = hero.findByType("soldier")
# Create a variable containing your archers.
archers = hero.findByType("archer")
for i in range(len(soldiers)):
soldier = soldiers[i]
commandSoldier(soldier, i, len(soldiers));
archer = archers[i]
commandArcher(archer, i, len(archers));

# use commandArcher() to command your archers``````

Can someone help me with this ?

Please, format you code. Indents in Python are important and it’s hard to read your code. Use that link to learn how to do it: FAQ - Check Before Posting