Reaping Fire Python Heeeellllllp

I really don’t get what is wrong with my code, please help! Thank you :smiling_face_with_three_hearts:

# 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"
    fangrider = hero.findNearest(hero.findByType("fangrider", hero.findEnemies()))
    if fangrider and fangrider.pos.x < 37:
        return "fight-back"
    # Otherwise, return "collect-coins"
    else:
        return "collect-coins"

def commandAttack():
    # Command your griffin riders to attack ogres.
    for friend in hero.findFriends():
        if friend.type == "griffin-rider":
            enemy = friend.findNearestEnemy()
            if enemy and enemy.type != "fangrider":
                hero.command(friend, "attack", enemy)
    pass

def pickUpCoin():
    # Collect coins
    coin = hero.findNearestItem()
    hero.move(coin.pos)
    pass

def heroAttack():
    # Your hero should attack fang riders that cross the minefield.
    enemy = hero.findNearest(hero.findByType("fangrider"))
    if enemy.pos.x < 37:
        hero.attack(enemy)
    pass

while True:
    commandAttack()
    strategy = chooseStrategy()
    # Call a function, depending on what the current strategy is.
    if (strategy == "griffin-rider"):
        commandAttack()
    elif(strategy == "fight-back"):
        heroAttack()
    else:
        pickUpCoin()

The griffin-riders will go to the fire-traps because the fangriders go there and then KABOOM!

try making this
if friend and friend.type == "griffin-rider"

im not sure how effective these would be but doesnt harm to try

and for this try using
hero.moveXY(coin.pos.x, coin.pos.y)

also here make it:
if enemy and enemy.pos.x < 37:

1 Like

Your code is working fine for me, but here are a few suggestions

fangrider = hero.findNearest(hero.findByType("fangrider", hero.findEnemies()))

From the code I see, your “fight-back” method isn’t being called. The method findByType() takes only 1 argument, fangriders are always enemies, make sure to remove that so that the function would work.
fangrider = hero.findNearest(hero.findByType("fangrider"))

Also sometimes your code might face a seed problem, so you will have to resubmit multiple times.

1 Like

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