[SOLVED] Reaping Fire Help (python)

# 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!

The only issue in your code is you’re not necessarily checking if the fangrider is really on your side. You’re only checking if the distance from your hero to the fangrider is less than 30, which means this situation will still allow the fangrider to access your side.


However you can see that the minefield starts at around x = 38, so you can replace the hero.distanceTo(enemy) < 30: part with enemy.pos.x < 30

2 Likes

Thanks! Now that I see it, it makes sense. Thx

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