Help on Reaping Fire!

My code works until the enemies come and my hero is not summoning griffin-riders.

Here is my code:


# The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.

def chooseStrategy():
    enemy = hero.findNearest(hero.findEnemies())
    # If you can summon a griffin-rider, return "griffin-rider"
    if hero.costOf("griffin-rider") == hero.gold:
        return "griffin-rider"
    # If there is a fangrider on your side of the mines, return "fight-back"
    if enemy and enemy.type is "fangrider" and hero.distanceTo(enemy) > 10:
        return "fight-back"
    # Otherwise, return "collect-coins"
    else:
        return "collect-coins"

def commandAttack():
    enemy = hero.findNearest(hero.findEnemies())
    # Command your griffin riders to attack ogres.
    if enemy and enemy.type is "ogre":
        hero.command("griffin-rider", "attack", "ogre")
    pass
    
def pickUpCoin():
    # Collect coins
    item = hero.findNearest(hero.findItems())
    if item:
        hero.moveXY(item.pos.x, item.pos.y)
    pass
    
def heroAttack():
    enemy = hero.findNearest(hero.findEnemies())
    # Your hero should attack fang riders that cross the minefield.
    if enemy and enemy.type is "fangrider" and hero.distanceTo(enemy) > 10:
        hero.attack(enemy)
    pass
while True:
    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()

In the future select your whole code and press this button-

# The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.

def chooseStrategy():
    enemy = hero.findNearest(hero.findEnemies())
    # If you can summon a griffin-rider, return "griffin-rider"
    if hero.costOf("griffin-rider") == hero.gold:
        return "griffin-rider"
    # If there is a fangrider on your side of the mines, return "fight-back"
    if enemy and enemy.type is "fangrider" and hero.distanceTo(enemy) > 10:
        return "fight-back"
    # Otherwise, return "collect-coins"
    else:
        return "collect-coins"

def commandAttack():
    enemy = hero.findNearest(hero.findEnemies())
    # Command your griffin riders to attack ogres.
    if enemy and enemy.type is "ogre":
        hero.command("griffin-rider", "attack", "ogre")
    pass

def pickUpCoin():
    # Collect coins
    item = hero.findNearest(hero.findItems())
    if item:
        hero.moveXY(item.pos.x, item.pos.y)
    pass

def heroAttack():
    enemy = hero.findNearest(hero.findEnemies())
    # Your hero should attack fang riders that cross the minefield.
    if enemy and enemy.type is "fangrider" and hero.distanceTo(enemy) > 10:
        hero.attack(enemy)
    pass
while True:
    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()

I did not change your code at all. All I did was making easier to read.:slightly_smiling_face:

2 Likes

please do not give out the working code.

1 Like

I didn’t. All I did was making it easier to read.

2 Likes