New Level: Grim Determination

Oh, well, you have to command your peasants to collect coins so that you can summon a griffin-rider in the first place, right?

i have griffins summoned already. But they dont do anything

so i fixed the griffin problem, but when my peasants get gold, they just hide in the corner…

Can you show us your function for commanding your peasants to collect coins?

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 paladin:
lowPaladin = lowestHealthPaladin()
if lowPaladin:
if paladin.canCast(“heal”):
self.command(paladin, “cast”, “heal”, lowPaladin)
else:
self.command(paladin, “shield”)
def commandFriends():
# Command your friends.
friends = self.findFriends()
for friend in friends:
if friend.type == “peasant”:
commandPeasant(friend)
elif friend.type == “griffin-rider”:
commandGriffin(friend)
elif friend.type == “paladin”:
commandPaladin(friend)

def commandGriffin(griffin):
enemy = griffin.findNearest(griffin.findEnemies())
if enemy:
self.command(griffin, “attack”, enemy)
def commandPeasant(peasant):
item = peasant.findNearest(peasant.findItems())
self.command(peasant, “move”, item.pos)
loop:
commandFriends()
# Summon griffin riders!
if self.gold >= self.costOf(“griffin-rider”):
self.summon(“griffin-rider”)

please can you help .i don’t hold back the enemy enough. my paladin’s heal and all but don’t succeed. same with griffins

Your paladins are not attacking. If they are not healing they should attack, not shield.
You can make them shield when they are very low on health if you really want.

Thanks i’ll try it and the branches idea confused me and the code didn’t work at all.

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 paladin:
lowPaladin = lowestHealthPaladin()
if lowPaladin:
paladin.canCast(“heal”)
self.command(paladin, “cast”, “heal”, lowPaladin)
else:
enemy2 = paladin.findNearest(paladin.findEnemies())
if enemy2:
self.command(paladin, “attack”, enemy2)
def commandFriends():
# Command your friends.
friends = self.findFriends()
for friend in friends:
if friend.type == “peasant”:
commandPeasant(friend)
elif friend.type == “griffin-rider”:
commandGriffin(friend)
elif friend.type == “paladin”:
commandPaladin(friend)

def commandGriffin(griffin):
enemy1 = griffin.findNearest(griffin.findEnemies())
if enemy1:
self.command(griffin, “attack”, enemy1)
def commandPeasant(peasant):
item = peasant.findNearest(peasant.findItems())
self.command(peasant, “move”, item.pos)
loop:
commandFriends()
# Summon griffin riders!
if self.gold >= self.costOf(“griffin-rider”):
self.summon(“griffin-rider”)
indent preformatted text by 4 spaces
I tried the code and it didn’t work.:worried:

Format the code by surrounding by 3 back-quotes (to left on your keyboard):

code here

  1. Do not use so many branched ifs. In commandPaladin add a return after each self.command instruction.
    In this way you do not need to guard your instructions by an else

  2. paladin.canCast('heal") returns a true/false expression: you must test this expression in an if just like you have done for isReady("cleave"):

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 not paladin:
        return
    lowPaladin = lowestHealthPaladin()
    if lowPaladin:
        if paladin.canCast("heal"):
            self.command(paladin, "cast", "heal", lowPaladin)
            return
    enemy2 = paladin.findNearest(paladin.findEnemies())
    if enemy2:
        self.command(paladin, "attack", enemy2)
        return
# you can add code for shield or move here
# if (condition to shield)
#     shield
#     return
1 Like

Thank you, i did it!