My hero does not attack the fangriders. This is my code:
def chooseStrategy():
enemies = hero.findEnemies()
# If you can summon a griffin-rider, return "griffin-rider"
if hero.gold >= hero.costOf("griffin-rider"):
hero.summon("griffin-rider")
return "griffin-rider"
if enemy and enemy.type == "fangrider":
return "fight-back"
else:
return "collect-coins"
# If there is a fangrider on your side of the mines, return "fight-back"
# Otherwise, return "collect-coins"
def commandAttack():
# Command your griffin riders to attack ogres.
friend = hero.findNearest(hero.findFriends())
enemy = hero.findNearest(hero.findEnemies())
friends = hero.findFriends()
enemies = hero.findEnemies()
for friend in friends:
if friend.type == "griffin-rider":
hero.command(friend, "attack", enemy)
pass
def pickUpCoin():
# Collect coins
item = hero.findNearestItem()
if item:
hero.moveXY(item.pos.x,item.pos.y)
pass
def heroAttack():
# Your hero should attack fang riders that cross the minefield.
posX = enemy.pos.x
type = hero.findByType("fangrider")
enemy = hero.findNearest(type)
if enemy and enemy.type == "fangrider" and posX < 37:
hero.attack(enemy)
pass
while True:
commandAttack()
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
if strategy == "griffin-rider":
commandAttack()
if strategy == "fight-back":
heroAttack()
if strategy == "collect-coins":
pickUpCoin()```