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)
while True:
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()