# Grim determination HELP anyone

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.
lowestHealth = 99999
lowestFriend = None
friends = hero.findFriends()
for friend in friends:
continue
if friend.health < lowestHealth and friend.health < friend.maxHealth:
lowestHealth = friend.health
lowestFriend = friend

return lowestFriend

target = hero.findNearestEnemy()
# And don't forget, they can attack, too!
if 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():
friends = hero.findFriends()
for friend in friends:
if friend.type == "peasant":
commandPeasant(friend)
pass
elif friend.type == "griffin-rider":
commandGriffin(friend)
pass

while True:
commandFriends()
# Summon griffin riders!
hero.summon("griffin-rider")
``````

You can delete this.

Why are you using the variabile friend when you need to use the variabile peasant?

Here what happens if you do not have enough gold to summon a griffin rider?

Here don’t you want to find the paladin’s nearest target?

Here don’t you want to put what that function returns into a variable (like lowest)?

Here why do you heal the enemy instead of the lowest paladin?

The shield command doesn’t require any parameters, so you can delete the , target part from here.

Andrei

3 Likes

can i command to build a fence if yes, how?

Only you can build a fence, peasants can not do that.

Andrei

2 Likes

And this structure will never ever work as intended :

``````    if paladin.canCast("heal"):
if target: