Grim Determination: WHERE DID I GO WRONG!

I don’t know why the heck this is happening and I need help! By the way I can help out again. Sorry for being away for so long. Here is my code so you can help me:

# Your goal is to protect Reynaldo

# Find the paladin with the lowest health.
def lowestHealthPaladin():
    lowestHealth = 99999
    lowestFriend = None
    friends = self.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!
    
    if friend and friend.type is "paladin":
        enemies = friend.findEnemies()
        enemy = friend.findNearest(enemies) 
        if lowestFriend:
            self.command(paladin, "cast", "heal", lowestFriend)
        if enemy:
            self.command(paladin, "attack", enemy)
        if paladin.health < 300:
            self.command(paladin, "shield")
            paladin.canCast("heal")
        

def commandFriends():
    # Command your friends.
    friends = self.findFriends()
    for friend in friends:
        if friend.type == "peasant":
            def commandPeasant(friend):
                coins = friend.findItems()
                coin = friend.findNearest(coins)
                if coin:
                    coinPosition = coin.pos
                    peasants = self.findByType("peasant", friends)
                    peasant = self.findNearest(peasants)
                    self.command(peasant, "move", coinPosition)
        elif friend.type == "griffin-rider":
            def commandGriffin(friend):
                if friend and friend.type is "griffin-rider":
                    self.command(friend, "attack", enemy)
        elif friend.type == "paladin":
            commandPaladin(friend)

loop:
    commandFriends()
    # Summon griffin riders!
    enemy = self.findNearest(self.findEnemies())
    if enemy and self.gold >= self.costOf("griffin-rider"):
        self.summon("griffin-rider")
    friends = self.findFriends()
    friend = self.findNearest(self.findFriends())
    paladins = self.findByType("paladin", friends)
    paladin = self.findNearest(paladins)
    commandPaladin(paladin)

FYI I have an error on this line:

elif friend.type == "paladin":
            commandPaladin(friend)

Looks like your code still has all the issues that I’ve mentioned in your previous thread.

Any reason to not keep using the old thread? It would be better to avoid creating duplicate topics for the same problem.

1 Like