# The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.
def chooseStrategy():
enemies = hero.findEnemies()
enemy = hero.findNearest(enemies)
# 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 there is a fangrider on your side of the mines, return "fight-back"
elif enemy and enemy.type == "fangrider" and hero.distanceTo(enemy) < 30:
return "fight-back"
# Otherwise, return "collect-coins"
else:
return "collect-coins"
def commandAttack():
# Command your griffin riders to attack ogres.
for griffin in hero.findByType("griffin-rider"):
if griffin:
enemy = griffin.findNearestEnemy()
if enemy and enemy.type != "fangrider":
hero.command(griffin, "attack", enemy)
def pickUpCoin():
# Collect coins
item = hero.findNearestItem()
if item:
hero.move(item.pos)
pass
def heroAttack():
# Your hero should attack fang riders that cross the minefield.
target = hero.findNearest(hero.findByType("fangrider"))
if target:
hero.attack(target)
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()
This is my code, but it just barely doesn’t protect the minefield long enough. The griffin riders stay in place after I summon two of them until one of the other two dies, so it creates enough enemies that the griffin riders can’t kill all of them. If you were wondering, the link is https://codecombat.com/play/level/reaping-fire
Please help!