hi
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":
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!
weakestPaladin = lowestHealthPaladin()
enemy = paladin.findNearestEnemy()
if enemy:
distance = paladin.distanceTo(enemy)
if distance < 20 and enemy.health > 0:
hero.command(paladin, "attack", enemy)
if paladin.health < paladin.maxHealth / 3:
hero.command(paladin, "shield")
if weakestPaladin:
if paladin.canCast('heal'):
hero.command(paladin, "cast", 'heal', weakestPaladin)
pass
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"):
hero.resetCooldown("haste")
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":
commandPeasant(friend)
pass
elif friend.type == "griffin-rider":
commandGriffin(friend)
pass
elif friend.type == "paladin":
commandPaladin(friend)
while True:
commandFriends()
# Summon griffin riders!
if hero.gold > hero.costOf("griffin-rider"):
hero.summon('griffin-rider')