# Grim Determination SOS

**URL:** <https://discourse.codecombat.com/t/grim-determination-sos/22642>\
**Category:** Level Help\
**Created:** [June 30, 2020, 7:00am UTC](https://discourse.codecombat.com/t/grim-determination-sos/22642 "2020-06-30T07:00:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ww2\_tanker](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ww2_tanker/32/13409_2.png) [@ww2\_tanker](https://discourse.codecombat.com/u/ww2_tanker)\
**Post date:** [June 30, 2020, 7:00am UTC](https://discourse.codecombat.com/t/grim-determination-sos/22642/1 "2020-06-30T07:00:50Z")

</div>

Here is my code:

```python
# Your goal is to protect Reynaldo

# Find the paladin with the lowest health.
def lowestHealthPaladin():
    lowestHealth = 99999
    lowestFriend = None
    friends = hero.findFriends()
    for friend in friends:
        if friend.type != "paladin":
            continue
        if friend.health < lowestHealth and friend.health < friend.maxHealth:
            lowestHealth = friend.health
            lowestFriend = friend

    return lowestFriend

def commandPaladin(paladin):
    # Heal the paladin with the lowest health using lowestHealthPaladin()
    # You can use paladin.canCast("heal") and command(paladin, "cast", "heal", target)
    # Paladins can also shield: command(paladin, "shield")
    # And don't forget, they can attack, too!
    paladin = hero.findNearest(hero.findByType("paladin"))
    if paladin.canCast("heal", hero):
        hero.command(paladin, "cast", "heal", hero)
        pass
    

def commandFriends():
    # Command your friends.
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "peasant":
            #commandPeasant(friend)
            pass
        elif friend.type == "griffin-rider":
            #commandGriffin(friend)
            pass
        elif friend.type == "paladin":
            commandPaladin(friend)

while True:
    commandFriends()
    # Summon griffin riders!
hero.summon("griffin-rider")

```

---

<div class="post-metadata">

**Author:** ![AnSeDra](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ansedra/32/13123_2.png) [@AnSeDra](https://discourse.codecombat.com/u/AnSeDra)\
**Post date:** [June 30, 2020, 7:21am UTC](https://discourse.codecombat.com/t/grim-determination-sos/22642/2 "2020-06-30T07:21:40Z")

</div>

> [@ww2\_tanker](#):
>
> ```python
> if paladin.canCast("heal", hero):
> hero.command(paladin, "cast", "heal", hero)
> 
> ```

Here instead of _hero_ put _lowest_. Before that put that lowest is what the function lowestHealthPaladin. And delete this:

> [@ww2\_tanker](#):
>
> `paladin = hero.findNearest(hero.findByType("paladin"))`

Also, command the paladin to attack or shield after you check if it can heal and after it does it.

> [@ww2\_tanker](#):
>
> `hero.summon("griffin-rider")`

This one put in an if that checks if hero.gold \>= 50 that is in the while loop.

> [@ww2\_tanker](#):
>
> `#commandGriffin(friend)`

Here write a function that commands the friend to attack their nearest enemy, and then delete the # from its beggining.

> [@ww2\_tanker](#):
>
> `#commandPeasant(friend)`

Here command the friend to move to their nearest coin, and then delet the # from its beggining.

Andrei
