# Toil and Trouble-- solvable with wrong strategy

**URL:** <https://discourse.codecombat.com/t/toil-and-trouble-solvable-with-wrong-strategy/3719>\
**Category:** Adventurer\
**Created:** [April 30, 2015, 2:34am UTC](https://discourse.codecombat.com/t/toil-and-trouble-solvable-with-wrong-strategy/3719 "2015-04-30T02:34:22Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![trotod](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/trotod/32/3263_2.png) [@trotod](https://discourse.codecombat.com/u/trotod)\
**Post date:** [July 19, 2015, 12:00am UTC](https://discourse.codecombat.com/t/toil-and-trouble-solvable-with-wrong-strategy/3719/21 "2015-07-19T00:00:59Z")

</div>

Try fixing up your indentation. The syntax checker isn’t all that perfect when spitting out the error message.

---

<div class="post-metadata">

**Author:** ![midnightdream](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@midnightdream](https://discourse.codecombat.com/u/midnightdream)\
**Post date:** [July 19, 2015, 7:17am UTC](https://discourse.codecombat.com/t/toil-and-trouble-solvable-with-wrong-strategy/3719/22 "2015-07-19T07:17:38Z")

</div>

Okay, I fixed it and it is now error free:

```python
def ChooseTarget(friend):
    enemies = self.findEnemies()
    witches = self.findByType("witch", enemies)
    if friend.type == "soldier":
        target = friend.findNearest(witches)
    elif friend.type == "archer":
        target = friend.findNearest(enemies)
    return target
       
loop:   
    friends = self.findFriends()       
    for friend in friends:
            target = ChooseTarget(friend)
            #self.say("Friend is " + friend + "and target is " + target)
            self.command(friend, "attack", target)

```

For some reason, my archers all bunch together and move to the top. So the throwers on the bottom live.

Then they attack the Ogre on the top while my soldiers move forward to attack the witches. Eventually the top Ogre and the bottom witch die, but the remaining throwers, Ogre and Witch mow down what is left of my forces at that point.

I have already gone through this and many other variations which is why I may have appeared to have been overthinking it earlier. Any help at this point would be much appreciated.

Edit: Okay, I got it. The problem was, my hero apparently couldn’t see the throwers on the bottom. I changed enemies to friend.findEnemies() as you suggested and it worked.

Thanks a bunch trotod!

---

<div class="post-metadata">

**Author:** ![chrstn1](https://avatars.discourse-cdn.com/v4/letter/c/c0e974/32.png) [@chrstn1](https://discourse.codecombat.com/u/chrstn1)\
**Post date:** [December 27, 2016, 11:23am UTC](https://discourse.codecombat.com/t/toil-and-trouble-solvable-with-wrong-strategy/3719/23 "2016-12-27T11:23:01Z")

</div>

For me, unfortunately, this code doesn’t work ☹

[Previous page](https://discourse.codecombat.com/t/toil-and-trouble-solvable-with-wrong-strategy/3719.md?page=1)
