here is the link of the level
it says “fix youre code ‘try hero.distanceTo()’”
here is my code
if target.distance < paladin.distance:
my full code
# 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):
target = hero.findNearestEnemy()
# 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!
lowestHealthPaladin()
if paladin.canCast("heal"):
if target:
hero.command(paladin, "cast", "heal", target)
if paladin:
hero.command(paladin, "shield", target)
hero.command(paladin, "attack", target)
pass
def commandGriffin(griffin):
firend = hero.findFriends()
if friend.type == "griffin-rider":
enemy = griffin.findEnemies()
if enemy:
hero.command(friend, "attack", enemy)
def commandPeasant(peasant):
friend = hero.findFriends()
if friend.type == "peasant":
coin = hero.findNearestItem()
if coin:
hero.command(friend, "move", {'x': coin.pos.x, 'y': coin.pos.y})
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!
hero.summon("griffin-rider")