How can I make a block of code where if the Fangrider’s x position is less than the right edge of the minefield, the griffin riders disengage from it and attack other ogres while my hero stops collecting coins and goes to attack the Fangrider. My code is posted down below.
# The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.
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 there is a fangrider on your side of the mines, return "fight-back"
fangriders = hero.findByType("fang-rider")
if fangriders:
for i in range(len(fangriders)):
fangrider = fangriders[i]
if fangrider.pos.x < 38:
return "fight-back"
# Otherwise, return "collect-coins"
else:
return "collect-coins"
def commandAttack():
# Command your griffin riders to attack ogres.
griffinriders = hero.findByType("griffin-rider")
for i in range(len(griffinriders)):
griffinrider = griffinriders[i]
enemy = hero.findNearestEnemy()
if enemy and enemy.type != "fang-rider":
hero.command(griffinrider, "attack", enemy)
pass
def pickUpCoin():
# Collect coins
item = hero.findNearestItem()
hero.moveXY(item.pos.x, item.pos.y)
pass
def heroAttack():
# Your hero should attack fang riders that cross the minefield.
fangriders = hero.findByType("fang-rider")
for i in range(len(fangriders)):
if fangriders[i].pos.x < 38:
hero.attack(fangriders[i])
pass
while True:
commandAttack()
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
if "griffin-rider":
commandAttack()
if "fang-rider":
heroAttack()
if "collect-coins":
pickUpCoin()