Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Grim Determination SOS

Here is my code:

# 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")

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

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

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

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

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

Andrei

1 Like