The biggest problem with this code is while being faulty it works!
riders = hero.findByType("griffin-rider", hero.findFriends())
# riders = hero.findByType("griffin-rider") # all griffins are friends
# not an error but needless computations
enemies = hero.findEnemies()
if enemies: # will be always true even when there are no enemies
# code
if nearest and riders: # if nearest exists check will be always true
# if riders true even when there are no riders
# code
coins = hero.findItems()
if coins: # always true even when there are no coins
# code
peasants = hero.findByType("peasant", hero.findFriends())
# not an error: simply hero.findByType("peasant")
if peasants: # always true even when there are no peasants
# code
return((deltaX**2)+(deltaY**2)**0.5)
# last round bracket is misplaced