# Library Tactitian- python

**URL:** <https://discourse.codecombat.com/t/library-tactitian-python/10450>\
**Category:** Uncategorized\
**Created:** [February 4, 2017, 8:32pm UTC](https://discourse.codecombat.com/t/library-tactitian-python/10450 "2017-02-04T20:32:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicholas\_Horton](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/nicholas_horton/32/5621_2.png) [@Nicholas\_Horton](https://discourse.codecombat.com/u/Nicholas_Horton)\
**Post date:** [February 4, 2017, 8:32pm UTC](https://discourse.codecombat.com/t/library-tactitian-python/10450/1 "2017-02-04T20:32:37Z")

</div>

I’m having some trouble seeing what I’m doing wrong. If someone could point me in the right direction it would be very appreciated. Thanks.

```python
# 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()
    # Figure out which enemy has the most health, and set bestTarget to be that enemy.
    enemyIndex=0
    if enemyIndex < len(enemies):
        enemy = enemies[enemyIndex]
        if enemy.health > mostHealth:
            mostHealth = enemy.health
            bestTarget = enemy
        enemyIndex += 1
        return bestTarget
    # 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.
    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 j in range(len(archers)):
        archer = archers[j]
        commandArcher(archer);

```

---

<div class="post-metadata">

**Author:** ![FlowerChi](https://avatars.discourse-cdn.com/v4/letter/f/71c47a/32.png) [@FlowerChi](https://discourse.codecombat.com/u/FlowerChi)\
**Post date:** [February 5, 2017, 3:01am UTC](https://discourse.codecombat.com/t/library-tactitian-python/10450/2 "2017-02-05T03:01:43Z")

</div>

I think your FindStrongest function has a problem. You indented your

```python
return bestTarget

```

one too much so that it would return more than one. You need to put it back so that it will only send one enemy after the function found out which one is the strongest.

---

<div class="post-metadata">

**Author:** ![jack225](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jack225/32/5644_2.png) [@jack225](https://discourse.codecombat.com/u/jack225)\
**Post date:** [February 5, 2017, 10:53am UTC](https://discourse.codecombat.com/t/library-tactitian-python/10450/3 "2017-02-05T10:53:35Z")

</div>

#not:  
if enemyIndex \< len(enemies):  
…enemy = enemies[enemyIndex]  
#but:  
while enemyIndex \< len(enemies):  
…enemy = enemies[enemyIndex]

---

<div class="post-metadata">

**Author:** ![Adam\_King](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/adam_king/32/2705_2.png) [@Adam\_King](https://discourse.codecombat.com/u/Adam_King)\
**Post date:** [January 17, 2018, 6:27pm UTC](https://discourse.codecombat.com/t/library-tactitian-python/10450/4 "2018-01-17T18:27:56Z")

</div>

![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/b/bde5e5fa824e67ced1984ce4968f3d0b99a19120.png)  
what does this error mean?

---

<div class="post-metadata">

**Author:** ![Adam\_King](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/adam_king/32/2705_2.png) [@Adam\_King](https://discourse.codecombat.com/u/Adam_King)\
**Post date:** [March 12, 2018, 5:45pm UTC](https://discourse.codecombat.com/t/library-tactitian-python/10450/5 "2018-03-12T17:45:02Z")

</div>

That error somehow disappeared but now I don’t know what I am doing wrong, another error message popped up.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/d/d5cccddac43b86dc744df06b53de7c89ceda0aba.jpg)

---

<div class="post-metadata">

**Author:** ![MunkeyShynes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munkeyshynes/32/9277_2.png) [@MunkeyShynes](https://discourse.codecombat.com/u/MunkeyShynes)\
**Post date:** [March 12, 2018, 11:20pm UTC](https://discourse.codecombat.com/t/library-tactitian-python/10450/6 "2018-03-12T23:20:34Z")

</div>

Look closely at line 34. Why are you defining nearest as find nearest librarian AND find nearest enemy? Who actually needs to find what here? The object here shouldn’t be hero and your archers don’t have a reason to be looking for librarians. Keep it simple.

---

<div class="post-metadata">

**Author:** ![Adam\_King](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/adam_king/32/2705_2.png) [@Adam\_King](https://discourse.codecombat.com/u/Adam_King)\
**Post date:** [March 13, 2018, 5:24pm UTC](https://discourse.codecombat.com/t/library-tactitian-python/10450/7 "2018-03-13T17:24:30Z")

</div>

I got that, except now it keeps saying that archer has no function to find nearest enemy.

---

<div class="post-metadata">

**Author:** ![MunkeyShynes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munkeyshynes/32/9277_2.png) [@MunkeyShynes](https://discourse.codecombat.com/u/MunkeyShynes)\
**Post date:** [March 13, 2018, 6:14pm UTC](https://discourse.codecombat.com/t/library-tactitian-python/10450/8 "2018-03-13T18:14:45Z")

</div>

I wasn’t saying to delete line 34, I meant it needs to be changed. You need to define nearest properly.
