Library tactics help pls!

This is my code so far.

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);

def findStrongestTarget():
    mostHealth = 0
    bestTarget = None
    enemies = hero.findEnemies()
    if enemies.health > mostHealth:
        bestTarget = enemy
    if bestTarget and bestTarget.health > 15:
        return bestTarget
    else:
        return None

def commandArcher(archer):
    nearest = archer.findNearestEnemy()
    if archerTarget:
        hero.command(archer, "attack", archerTarget)
    elif nearest:
        hero.command(archer, "attack", nearest)
archerTarget = None
while True:
    if not archerTarget or archerTarget.health <= 0:
        archerTarget = findStrongestTarget()
    friends = hero.findFriends()
    soldiers = hero.findByType("soldier")
    for i in range(len(soldiers)):
        soldier = soldiers[i]
        commandSoldier(soldier, i, len(soldiers));
    hero.command('archer', "attack", enemy)

After the

while True:
    if not archerTarget or archerTarget.health <= 0:
        archerTarget = findStrongestTarget()
    friends = hero.findFriends()
    soldiers = hero.findByType("soldier")

chunk, it says to

# Create a variable containing your archers.

so if you look at the line soldiers = hero.findByType("soldier"), it’s an example of a variable with all of your soldiers. Maybe try to change something to make it all of your archers instead of your soldiers? (and don’t ask me to give you the answer)

But that was in the starting code…

hero.command('archer', "attack", enemy)

This line seems to have a lot of errors in it when I tested your code

1 Like
  1. I think you forgot to use your commandArcher function
  2. Your archers are having trouble finding their “nearestEnemy”

no im saying make another line of code to do archers instead of soldiers

Ok. I will try that.