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

I'm stuck on grim determination

please help, I can’t seem to pass the level grim determination.

Hi @hello_there,
please could you post your code onto the forum so I can copy it and test it. Here’s a topic which tells you how to format your code:


Thanks
Danny

# 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):
    enemyMissiles = hero.findEnemyMissiles()
    missile = hero.findNearest(enemyMissiles)
    # Heal the paladin with the lowest health using 
    enemy = hero.findNearestEnemy()
    if lowestHealthPaladin():
        if paladin.canCast("heal", lowestHealthPaladin()):
            hero.command(paladin, "cast", "heal", 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!
    
    if enemy:
        hero.command(paladin, "attack", enemy)
    pass
def commandPeasant(friend):
    item = friend.findNearestItem()
    if item:
        hero.command(friend, "move", item.pos)
    pass
def commandGriffin(friend):
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type=="warlock":
        hero.command(friend, "attack", enemy)
    else:
        hero.command(friend, "defend", friend.pos)
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)
            pass
while True:
    commandFriends()
    enemy = hero.findNearestEnemy()
    # Summon griffin riders!
    if hero.gold>=hero.costOf("griffin-rider"):
        hero.summon("griffin-rider")

Two changes that I’d recommend:

  1. commandGriffin
    • Have your griffins target the warlock first (as you are doing)
    • If there is no warlock, have them attack nearest, rather than defend
  2. commandPaladin - As the comments state, don’t forget that your paladins can shield too
    • Test to see if the paladin can cast heal
      • heal lowest if can
    • otherwise, if paladin’s health is below a certain level
      • shield
    • none of the above are true
      • if enemy
      • attack nearest

No worries i already completed the level

Hi @hello_there, please don’t post solutions. Please could you delete that post.
Thanks
Danny