Help on library tactitian

here is my code:
pls help

Hushbaum has been ambushed by ogres!

She is busy healing her soldiers, you should command them to fight!

The ogres will send more troops if they think they can get to Hushbaum or your archers, so keep them inside the circle!

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);
if (soldier.health > 60):
hero.command(soldier, “defend”, defendPos)
else:
hero.command(soldier, “defend”, {‘x’: 42, ‘y’: 40})

Find the strongest target (most health)

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

def findStrongestTarget():
mostHealth = 0
bestTarget = None
enemies = hero.findEnemies()
# Figure out which enemy has the most health, and set bestTarget to be that 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.findNearestEnemy()
if archerTarget:
hero.command(archer, “attack”, archerTarget)
elif nearest:
hero.command(archer, “attack”, nearest)

archerTarget = None

while True:
# If archerTarget is defeated 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.
acherTarget = findStrongestTarget()
for i in range(len(soldiers)):
    soldier = soldiers[i]
    commandSoldier(soldier, i, len(soldiers));
hero.command(archer, "attack", archerTarget)
 # use commandArcher() to command your archers
# Hushbaum has been ambushed by ogres!
# She is busy healing her soldiers, you should command them to fight!
# The ogres will send more troops if they think they can get to Hushbaum or your archers, so keep them inside the circle!

# 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);
    if (soldier.health > 60):
        hero.command(soldier, "defend", defendPos)
    else:
        hero.command(soldier, "defend", {'x': 42, 'y': 40})

# Find the strongest target (most health)
# This function returns something! When you call the function, you will get some value back.
def findStrongestTarget():
    mostHealth = 0
    bestTarget = None
    enemies = hero.findEnemies()
    # Figure out which enemy has the most health, and set bestTarget to be that 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.findNearestEnemy()
    if archerTarget:
        hero.command(archer, "attack", archerTarget)
    elif nearest:
        hero.command(archer, "attack", nearest)

archerTarget = None

while True:
    # If archerTarget is defeated 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.
    acherTarget = findStrongestTarget()
    for i in range(len(soldiers)):
        soldier = soldiers[i]
        commandSoldier(soldier, i, len(soldiers));
    hero.command(archer, "attack", archerTarget)
     # use commandArcher() to command your archers
   

Hi @Corgi and welcome to the forum! :partying_face:

Try to put this

In a for archer in archers loop.
In between those two comments

Try to make a for loop that goes through all elements from the enemies array and finds out the enemy with the most health and put it in the variabile bestTarget (as you did in the level with the big archer from the desert)
Do you need any more assistance at this level?

ok i’ve done that
now it saying archer not difined :face_with_raised_eyebrow:
screenshot-codecombat.com-2020.06.25-16_14_19

thx

[en_US.composer.my_button_text]

Thank you for welcoming me!

1 Like

Can you show me your code?

it is the hilighted part

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

    archerTarget = None

That looks alright. Can you show me your whole code?

# Hushbaum has been ambushed by ogres!
# She is busy healing her soldiers, you should command them to fight!
# The ogres will send more troops if they think they can get to Hushbaum or your archers, so keep them inside the circle!

# 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);
    if (soldier.health > 60):
        hero.command(soldier, "defend", defendPos)
    else:
        hero.command(soldier, "defend", {'x': 42, 'y': 40})

# Find the strongest target (most health)
for archer in archers:
    # This function returns something! When you call the function, you will get some value back.
    def findStrongestTarget():
        mostHealth = 0
        bestTarget = None
        enemies = hero.findEnemies()
        # Figure out which enemy has the most health, and set bestTarget to be that 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.findNearestEnemy()
    if archerTarget:
        hero.command(archer, "attack", archerTarget)
    elif nearest:
        hero.command(archer, "attack", nearest)

    archerTarget = None

while True:
    # If archerTarget is defeated 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.
    acherTarget = findStrongestTarget()
    for i in range(len(soldiers)):
        soldier = soldiers[i]
        commandSoldier(soldier, i, len(soldiers));
    hero.command(archer, "attack", archerTarget)
    commandArcher()
     # use commandArcher() to command your archers
   

Here is the problem. Delete that, then loop through all the archers and put commandArcher(archer) for all of them.

here is my charicter
screenshot-codecombat.com-2020.06.25-16_25_05

This one you did not correct.

If you need any more help, just send me your code.

still doesn’t work :frowning:

# Hushbaum has been ambushed by ogres!
# She is busy healing her soldiers, you should command them to fight!
# The ogres will send more troops if they think they can get to Hushbaum or your archers, so keep them inside the circle!

# 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);
    if (soldier.health > 60):
        hero.command(soldier, "defend", defendPos)
    else:
        hero.command(soldier, "defend", {'x': 42, 'y': 40})

# Find the strongest target (most health)
for archer in archers:
    # This function returns something! When you call the function, you will get some value back.
    def findStrongestTarget():
        mostHealth = 0
        bestTarget = None
        enemies = hero.findEnemies()
        # Figure out which enemy has the most health, and set bestTarget to be that 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.findNearestEnemy()
    if archerTarget:
        hero.command(archer, "attack", archerTarget)
    elif nearest:
        hero.command(archer, "attack", nearest)

    archerTarget = None

while True:
    # If archerTarget is defeated 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.
    acherTarget = findStrongestTarget()
    for i in range(len(soldiers)):
        soldier = soldiers[i]
        commandSoldier(soldier, i, len(soldiers));# Hushbaum has been ambushed by ogres!
# She is busy healing her soldiers, you should command them to fight!
# The ogres will send more troops if they think they can get to Hushbaum or your archers, so keep them inside the circle!

# 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);
    if (soldier.health > 60):
        hero.command(soldier, "defend", defendPos)
    else:
        hero.command(soldier, "defend", {'x': 42, 'y': 40})

# Find the strongest target (most health)
for archer in archers:
    # This function returns something! When you call the function, you will get some value back.
    def findStrongestTarget():
        mostHealth = 0
        bestTarget = None
        enemies = hero.findEnemies()
        # Figure out which enemy has the most health, and set bestTarget to be that enemy.
        # Hushbaum has been ambushed by ogres!
# She is busy healing her soldiers, you should command them to fight!
# The ogres will send more troops if they think they can get to Hushbaum or your archers, so keep them inside the circle!

# 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);
    if (soldier.health > 60):
        hero.command(soldier, "defend", defendPos)
    else:
        hero.command(soldier, "defend", {'x': 42, 'y': 40})

# Find the strongest target (most health)
for archer in archers:
    # This function returns something! When you call the function, you will get some value back.
    def findStrongestTarget():
        mostHealth = 0
        bestTarget = None
        enemies = hero.findEnemies()
        # Figure out which enemy has the most health, and set bestTarget to be that enemy.
        # Hushbaum has been ambushed by ogres!
# She is busy healing her soldiers, you should command them to fight!
# The ogres will send more troops if they think they can get to Hushbaum or your archers, so keep them inside the circle!

# 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);
    if (soldier.health > 60):
        hero.command(soldier, "defend", defendPos)
    else:
        hero.command(soldier, "defend", {'x': 42, 'y': 40})

# Find the strongest target (most health)
for archer in archers:
    # This function returns something! When you call the function, you will get some value back.
    def findStrongestTarget():
        mostHealth = 0
        bestTarget = None
        enemies = hero.findEnemies()
        # Figure out which enemy has the most health, and set bestTarget to be that enemy.
        hero.command(archer, "attack", archerTarget)
        commandArcher()
        #   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.findNearestEnemy()
    if archerTarget:
        hero.command(archer, "attack", archerTarget)
    elif nearest:
        hero.command(archer, "attack", nearest)

    archerTarget = None

while True:
    # If archerTarget is defeated 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.
    acherTarget = findStrongestTarget()
    for i in range(len(soldiers)):
        soldier = soldiers[i]
        commandSoldier(soldier, i, len(soldiers));

     # use commandArcher() to command your archers
   

        #   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.findNearestEnemy()
    if archerTarget:
        hero.command(archer, "attack", archerTarget)
    elif nearest:
        hero.command(archer, "attack", nearest)

    archerTarget = None

while True:
    # If archerTarget is defeated 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.
    acherTarget = findStrongestTarget()
    for i in range(len(soldiers)):
        soldier = soldiers[i]
        commandSoldier(soldier, i, len(soldiers));
    hero.command(archer, "attack", archerTarget)
    commandArcher()
     # use commandArcher() to command your archers
   

        #   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.findNearestEnemy()
    if archerTarget:
        hero.command(archer, "attack", archerTarget)
    elif nearest:
        hero.command(archer, "attack", nearest)

    archerTarget = None

while True:
    # If archerTarget is defeated 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.
    acherTarget = findStrongestTarget()
    for i in range(len(soldiers)):
        soldier = soldiers[i]
        commandSoldier(soldier, i, len(soldiers));
    hero.command(archer, "attack", archerTarget)
    commandArcher()
     # use commandArcher() to command your archers
   

     # use commandArcher() to command your archers
   

Here put archerTarget instead of archerTarget. And you still did not correct what I told you to.

my code was to big so i reloaded the whole thing and i might need some help getting the right code back again :expressionless:

1 Like

Just copy the code that you posted and then make the changes I told you to do and then you can ask again if you get any more errors.

ok but i think it might have the same code in it more than what is nessersery

I need help.
I can’t get past a certain part. I have gotten to 55.1.
this is my code

# Hushbaum has been ambushed by ogres!
# She is busy healing her soldiers, you should command them to fight!
# The ogres will send more troops if they think they can get to Hushbaum or your archers, so keep them inside the circle!
# 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);

# Find the strongest target (most health)
# This function returns something! When you call the function, you will get some value back.
def findStrongestTarget():
    mostHealth = 0
    bestTarget = None
    enemies = hero.findEnemies()
    for enemy in enemies:
        if enemy.maxHealth > mostHealth:
            bestTarget = enemy
    # Figure out which enemy has the most health, and set bestTarget to be that enemy.
    # Only focus archers' fire if there is a big ogre.
    if bestTarget and bestTarget.health > 15:
        return bestTarget
    else:
        mostHealth = 0
        return None


# If the strongestTarget has more than 15 health, attack that target. Otherwise, attack the nearest target.
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 archerTarget is defeated or doesn't exist, find a new one.
    friends = hero.findFriends()
    soldiers = hero.findByType("soldier")
    
    
    
    if not archerTarget or archerTarget.health <= 0:
        # Set archerTarget to be the target that is returned by findStrongestTarget()
        archerTarget = findStrongestTarget()
    
    
    # Create a variable containing your archers.
    archers = hero.findByType("archer")
    for i in range(len(soldiers)):
        soldier = soldiers[i]
        commandSoldier(soldier, i, len(soldiers));
    # use commandArcher() to command your archers
    for team in archers:
        commandArcher(team)

this is my equipment
image