# Library Tactian October 2019

Hello! I have been working on this level for a while now I can’t seem to get all of the soldiers to stay alive. The same one always seems to die
`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)
self.command(soldier, “defend”, defendPos);
pass

def findStrongestTarget():
mostHealth = 0
enemies = self.findEnemies()
enemyIndex = 0
while len(enemies) > enemyIndex:
enemy = enemies[enemyIndex]
if enemy:
enemyIndex += 1
if enemy.health > mostHealth:
mostHealth = enemy.health
bestTarget = enemy
if bestTarget and bestTarget.health > 15:
return bestTarget
else:
return None
pass

def commandArcher(archer):
nearest = archer.findNearestEnemy()
if archerTarget:
self.command(archer, “attack”, archerTarget)
elif nearest:
self.command(archer, “attack”, nearest)

archerTarget = None

while True:
if self.gold > self.costOf(“soldier”):
self.summon(“soldier”)
if not archerTarget or archerTarget.health <= 0:
archerTarget = findStrongestTarget()
friends = self.findFriends()
soldiers = self.findByType(“soldier”)
archers = self.findByType(“archers”)
for i, soldier in enumerate(soldiers):
commandSoldier(soldier, i, len(soldiers));
for i in range(len(archers)):
archer = archers[i]
commandArcher(archer)`

What is the name of the level?

Library Tactician! (20)

have any suggestions?

@MunkeyShynes this is my code, do you see anything wrong with it??

Code
``````def commandSoldier(soldier, soldierIndex, numSoldiers):
enemy = hero.findEnemies()
angle = Math.PI * 2 * soldierIndex / numSoldiers
defendPos = {"x": 41, "y": 40}
defendPos.x += 10 * Math.cos(angle)
defendPos.y += 10 * Math.sin(angle)
if enemy:
self.command(soldier, "defend", defendPos)
pass

def findStrongestTarget():
mostHealth = 0
enemies = self.findEnemies()
enemyIndex = 0
while len(enemies) > enemyIndex:
enemy = enemies[enemyIndex]
if enemy:
enemyIndex += 1
if enemy.health > mostHealth:
mostHealth = enemy.health
bestTarget = enemy
if bestTarget and bestTarget.health > 15:
return bestTarget
else:
return None
pass

def commandArcher(archer):
nearest = archer.findNearestEnemy()
if archerTarget:
self.command(archer, "attack", archerTarget)
elif nearest:
self.command(archer, "attack", nearest)

archerTarget = None

while True:
if self.gold > self.costOf("soldier"):
self.summon("soldier")
if not archerTarget or archerTarget.health <= 0:
archerTarget = findStrongestTarget()
friends = self.findFriends()
soldiers = self.findByType("soldier")
archers = self.findByType("archers")
for i, soldier in enumerate(soldiers):
commandSoldier(soldier, i, len(soldiers));
for i in range(len(archers)):
archer = archers[i]
commandArcher(archer)
``````