Grim determination - weird codes


I’ve done the codes and succeeded the level already after the execution, but when I “submit” it, my codes failed somehow, and when I run the codes again, its’ not working anymore, so weird.

# 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":
        if < lowestHealth and < friend.maxHealth:
            lowestHealth =
            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!
    weakestPaladin = lowestHealthPaladin()        
    enemy = paladin.findNearestEnemy()
    if enemy:
        distance = paladin.distanceTo(enemy)
        if distance < 20 and > 0:
            hero.command(paladin, "attack", enemy)
    if < paladin.maxHealth / 3:
        hero.command(paladin, "shield")
    if weakestPaladin:
        if paladin.canCast('heal'):
            hero.command(paladin, "cast", 'heal', weakestPaladin)

def commandGriffin(griffin):
    enemy = griffin.findNearestEnemy()
    if enemy:
        hero.command(griffin, "attack", enemy)

def commandPeasant(peasant):
    if hero.canCast("haste", peasant):
        hero.cast("haste", peasant)
    if hero.isReady("reset-cooldown"):
    coin = peasant.findNearestItem()
    if coin:
        hero.command(peasant, "move", coin.pos)

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

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

when I ran the codes the second time, all the peasants, paladins, griffin riders stopped moving after around 15 seconds

Hmm, this code seems to be alright. But obviously something’s going wrong… Please could you post a screenshot of your equipment and the level screen.

I’d suggest:

  • commandPaladin
    1. You currently have a stack of several if statements. I would recommend nesting them, using the if/elif/else method
    2. I’d also recommend heal first, shield second, attack last (not sure this matters, but I think healing first is key, as it help keep the paladin in the fight longer)
1 Like

yeah, sure

Well, on your screen you seem to be winning… Try what @dedreous said, maybe that will make it work every time, not just sometimes.

1 Like