Problem on Reaping Fire

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

def chooseStrategy():
    enemies = hero.findEnemies()
    strategy = "no"
    # If you can summon a griffin-rider, return "griffin-rider"
    if hero.gold >= hero.costOf("griffin-rider"):
        strategy = "yes"
        return "griffin-rider"
    
    # If there is a fangrider on your side of the mines, return "fight-back"
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type == "fangrider":
        strategy = "yes"
        return "fight-back"
    # Otherwise, return "collect-coins"
    if strategy == "no":
        return "collect-coins"
def summonGriffins():
    hero.summon("griffin-rider")
def commandAttack():
    # Command your griffin riders to attack ogres.
    griffins = hero.findByType("griffin-rider")
    for griffin in griffins:
        enemy = griffin.findNearestEnemy()
        if enemy:
            hero.command(griffin, "attack", enemy)
    pass
    
def pickUpCoin():
    # Collect coins
    item = hero.findNearestItem()
    if item and item.pos.x < 38:
        hero.moveXY(item.pos.x, item.pos.y)
    pass
    
def heroAttack():
    # Your hero should attack fang riders that cross the minefield.
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
    pass
    
while True:
    commandAttack()
    strategy = chooseStrategy()
    # Call a function, depending on what the current strategy is.
    if strategy == "griffin-rider":
        summonGriffins()
    elif strategy == "fight-back":
        heroAttack()
    elif strategy == "collect-coins":
        pickUpCoin()

What do I do in this level? The munchkins keep triggering the fire-traps, even though I’ve told my griffin-riders to attack.

I’m sorry if this post is bad quality. This is my very first post.
Also, this is my first post.

Your code is working all fine. Only one small issue in your chooseStrategy method.

if enemy and enemy.type == "fangrider":
    strategy = "yes"
    return "fight-back"

The problem is that the system will return fight-back when the hero sees a fangrider, therefore triggering the hero to target it, and running over the minefield.

Fix: Just add a condition check, see if the fangrider is on our side, as we don’t want the hero to chase enemies that are across the minefield. We can achieve this by checking the x position in the enemy.pos dictionary.

if enemy and enemy.type == "fangrider" and enemy.pos.x < 35: # distance check
    strategy = "yes"
    return "fight-back"

Now it should work :slight_smile:

1 Like

Thank you for helping with the code. I did the same fix before I saw your suggestion. But still, thanks for the support!

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.