Sinistre determination (in python)

hello, I’m french, I can’t success this level …don’t know why. I don’t know what to do, every thing seem to be right…what can I do


# 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)
    blesse = lowestHealthPaladin()
    warlock = hero.findNearest(hero.findByType("warlock"))
    if blesse and paladin.canCast("heal"):
        #hero.say(paladin + " soigne " + blesse)
        hero.command(paladin, "cast", "heal", blesse)
    # Paladins can also shield: command(paladin, "shield")
    hero.command(paladin, "shield")
    # And don't forget, they can attack, too!
    if warlock :
        if paladin.health > paladin.maxhealth/4:
            hero.command(paladin, "attack", warlock)
        else:
            hero.command(paladin, "shield")
    defense = paladin.pos
    hero.command(paladin, "defend", defense)


def commandPeasant(friend):
    coin = friend.findNearest(friend.findItems())
    if coin :
        hero.command(friend, "move", coin.pos)


        
def commandGriffin(friend):
    warlock = friend.findNearestEnemy()
    if warlock :
        hero.command(friend, "attack", warlock)

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


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



need some help to success this level …

1 Like

Hello @Gui :grinning: and welcome to the forum :tada:
You need to do the commandPaladin() function

maybe the paladins can just shield went they have a low health(< 200) and always attack the warlocks? The griffin-rider’s can do the rest

hello, thanks, that not enough … all my paladin die

the fight never stop until my paladin die

Can you post your new code?

# 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)
    blesse = lowestHealthPaladin()
    warlock = hero.findNearest(hero.findByType("warlock"))
    if blesse and paladin.canCast("heal"):
        #hero.say(paladin + " soigne " + blesse)
        hero.command(paladin, "cast", "heal", blesse)
        # Paladins can also shield: command(paladin, "shield")
    hero.command(paladin, "shield")
    # And don't forget, they can attack, too!
    if warlock :
        if paladin.health > 300:
            hero.command(paladin, "attack", warlock)
    hero.command(paladin, "shield")
    defense = paladin.pos
    hero.command(paladin, "defend", defense)


def commandPeasant(friend):
    coin = friend.findNearest(friend.findItems())
    if coin :
        hero.command(friend, "move", coin.pos)


        
def commandGriffin(friend):
    warlock = friend.findNearestEnemy()
    if warlock :
        hero.command(friend, "attack", warlock)

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


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



I intend with 100, 200, and 300

    if warlock :
        hero.command(paladin, "attack", warlock)
    hero.command(paladin, "shield")
    defense = paladin.pos
    hero.command(paladin, "defend", defense)

normally, this is enough, but i don’t win … :frowning:

I would do

else:
    hero.command(paladin, "shield")

no I lose

    if warlock :
        if paladin.health > 200:
            hero.command(paladin, "attack", warlock)
        else :
            hero.command(paladin, "shield")
    hero.command(paladin, "shield")
    defense = paladin.pos
    hero.command(paladin, "defend", defense)

Hi Gui,

Congratulations on finding the solution :smiley:

However, please could you take down your code? One of the forum rules is not to post working code, so that other people coming after you can’t just copy it.

Thanks,

Jenny

1 Like

we can still see it with the pencil

ok, no pb, I delete my post :wink:

2 Likes

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.