def chooseStrategy():
enemies = hero.findEnemies()
fangriders = hero.findByType("fangrider")
for fangrider in fangriders:
if fangrider.pos.x > 34:
return "fight-back"
# 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"
# Otherwise, return "collect-coins"
else:
return "collect-coins"
def commandAttack():
# Command your griffin riders to attack ogres.
friends = hero.findFriends()
for friend in friends:
enemyF = friend.findNearestEnemy()
if friend.type == "griffin-rider":
hero.command(friend, "attack", enemyF)
pass
def pickUpCoin():
# Collect coins
item = hero.findNearestItem()
if item:
itemPos = item.pos
hero.move(itemPos)
pass
def heroAttack():
# Your hero should attack fang riders that cross the minefield.
enemies = hero.findEnemies()
for enemy in enemies:
if enemy.type == "fangrider":
if hero.isReady("throw"):
hero.throw(enemy)
else:
hero.scattershot(enemy)
hero.attack(enemy)
pass
while True:
commandAttack()
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
if strategy == "griffin-rider":
if hero.gold >= hero.costOf("griffin-rider"):
hero.summon("griffin-rider")
commandAttack()
elif strategy == "fight-back"
heroAttack()
elif strategy == "collect-coins":
pickUpCoin()
def chooseStrategy():
enemies = hero.findEnemies()
fangriders = hero.findByType("fangrider")
for fangrider in fangriders:
if fangrider.pos.x > 34:
return "fight-back"
# 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"
# Otherwise, return "collect-coins"
else:
return "collect-coins"
def commandAttack():
# Command your griffin riders to attack ogres.
friends = hero.findFriends()
for friend in friends:
enemyF = friend.findNearestEnemy()
if friend.type == "griffin-rider":
hero.command(friend, "attack", enemyF)
pass
def pickUpCoin():
# Collect coins
item = hero.findNearestItem()
if item:
itemPos = item.pos
hero.move(itemPos)
pass
def heroAttack():
# Your hero should attack fang riders that cross the minefield.
enemies = hero.findEnemies()
for enemy in enemies:
if enemy.type == "fangrider":
if hero.isReady("throw"):
hero.throw(enemy)
else:
hero.scattershot(enemy)
hero.attack(enemy)
pass
while True:
commandAttack()
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
if strategy == "griffin-rider":
if hero.gold >= hero.costOf("griffin-rider"):
hero.summon("griffin-rider")
commandAttack()
elif strategy == "fight-back":
heroAttack()
elif strategy == "collect-coins":
pickUpCoin()
@Lydia_Song, It looks like there are a couple of issues in your code just because you mixed up the order of them, but one main thing I see is this:
You donβt actually want to use else if (elif) statements for this, you only want to use if statements. If you would like to me to explain why you only want to use if statements, then I can explain that to you. Your code should look more like this:
while True:
pickUpCoin()
commandAttack()
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
if strategy == "griffin-rider":
hero.summon("griffin-rider")
if strategy == "fight-back":
heroAttack()
if strategy == "collect-coins":
pickUpCoin()
Another issue I see is this function:
It is up to you, but you might want to try using a warrior to simplify this because you only need a basic attack. You also donβt actually need to all that checking, because iβm pretty sure you did it before, so you should simplify your code to look more like this:
def heroAttack():
# Your hero should attack fang riders that cross the minefield
enemy = hero.findNearest(hero.findEnemies())
if enemy and hero.distanceTo(enemy) < 30 and enemy.pos.x < 38:
hero.attack(enemy)
I think that this happens because this function has some issues:
Your order of these commands is mixed up and you shouldnβt summon a griffin rider here. I think that you should change your code to look something more like this:
def chooseStrategy():
enemies = hero.findEnemies()
enemy = hero.findNearest(enemies)
if hero.gold >= hero.costOf("griffin-rider"):
return "griffin-rider"
# If you can summon a griffin-rider, return "griffin-rider"
elif enemy:
if enemy.type is "fangrider" and enemy.pos.x < 38:
return "fight-back"
# If there is a fangrider on your side of the mines, return "fight-back"
else:
return "collect-coins"
@Lydia_Song I think you should try and summon the griffin-riders before the fang-rider part? And there is also some code you need to refigure.
Hereβs what I mean:
Instead of that, put this:
def chooseStrategy():
enemies = hero.findEnemies()
# If you can summon a griffin-rider, return "griffin-rider"
if hero.gold >= hero.costOf("griffin-rider"):
return "griffin-rider"
# If there is a fangrider on your side of the mines, return "fight-back"
fangrider = None
fangrider = hero.findNearest(hero.findByType("fangrider", hero.findEnemies()))
if fangrider and fangrider.pos.x <= 36:
return "fight-back"
# Otherwise, return "collect-coins"
else:
return "collect-coins"