Grim determination!


#1
# Votre but est de protéger Reynaldo

# Trouvez le paladin avec le moins d'énergie
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!
    lowestFriend=lowestHealthPaladin()
    if lowestFriend and paladin.canCast("heal"):
        hero.command(paladin, "cast", "heal", lowestFriend)
    else:
        enemy=paladin.findNearest(paladin.findEnemies())
        if enemy:
            hero.command(paladin,"attack",enemy)
        else:
            hero.command(paladin,"shied")
    pass

def commandPeasant(friend):
    item=friend.findNearest(friend.findItems())
    if item:
        hero.command(friend,"move",{"x":item.pos.x,"y":item.pos.y})

def commandGriffin(friend):
    enemy=friend.findNearest(friend.findEnemies())
    if enemy:
        hero.command(friend,"attack",enemy)





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!
    if hero.gold>=hero.costOf("griffin-rider"):
        hero.summon("griffin-rider")

Hello, I can’t finish the exercice “grim Determination”. Here is my code. I look in other discussions, but Idon’t find any idees. Can you help me and give me the answer??


#2

You don’t command your peasants and riders.


#3

An other question. Hove can the hero say a word , than a variable and than a word in one phrase?
I use

hero.say("Hero",number,"is dead")

but it’s wrong. Have you an idea?


#4

Thank you :slight_smile:


#5

But I can’t finish this exercice with this code. Any other suggestions?


#6

I do the exercice with the same code and I won!!! Can you answer to my other question?


#7

You can concatenate strings using the + operator.

hero.say("Hero " + number + " is dead")