When I run my code, my hero continually tries to summon Griffin Riders, and, as you can imagine, stalls in place for a long time, which causes me to lose the level. Here is my code:
def chooseStrategy():
enemies = self.findEnemies()
enemy = self.findNearest(enemies)
if self.gold > self.costOf("griffin-rider"):
return "griffin-rider"
# If you can summon a griffin-rider, return "griffin-rider"
elif enemy:
if enemy.type is "fangrider" and self.distanceTo(enemy) < 30:
return "fight-back"
# If there is a fangrider on your side of the mines, return "fight-back"
else:
return "collect-coins"
# Otherwise, return "collect-coins"
def commandAttack():
# Command your griffin riders to attack ogres.
for griffin in self.findByType("griffin-rider"):
if griffin:
enemy = griffin.findNearestEnemy()
if enemy:
self.command(griffin, "attack", enemy)
def pickUpCoin():
# Collect coins
coin = self.findNearest(self.findItems())
if coin:
self.move(coin.pos)
def heroAttack():
# Your hero should attack fang riders that cross the minefield.
enemy = self.findNearest(self.findEnemies())
if enemy and self.distanceTo(enemy) < 30:
self.attack(enemy)
loop:
commandAttack()
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
if strategy = "griffin-rider":
self.summon("griffin-rider")
if strategy = "fight-back":
heroAttack()
if strategy = "collect-coins":
pickUpCoin()
What am I doing wrong?