Reaping fire level, solved!

I have read through the hints (which don’t really help btw) and all of the other topics about this level and i still can’t get my hero to do anything; my hero just stands there doing nothing.

Code
# 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"):
        return "griffin-rider"
    # If there is a fangrider on your side of the mines, return "fight-back"
    if enemy.type == "fangrider" and enemy.pos.x <= 36:
        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:
        hero.command(friend, "attack", enemy)
    pass
    
def pickUpCoin():
    # Collect coins
    item = hero.findNearestItem()
    if item:
        hero.moveXY(coin.pos.x, coin.pos.y)
    pass
    
def heroAttack():
    # Your hero should attack fang riders that cross the minefield.
    hero.attack(enemy)
    pass
    
while True:
    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()

you never told it to summon griffins, you can add it here:

without returning anything, so you summon instead of return

I changed my code a bit, but now it says this:
image

# 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"
    fang = hero.findNearest(hero.findByType("fangrider",enemies))
    if fang and fang.pos.x <= 36:
        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:
        enemy = friend.findNearestEnemy
        if enemy:
            hero.command(friend, "attack", enemy) #This line here
        else:
            hero.command(friend, "move", {'x':80,'y':40})
        
    pass
    
def pickUpCoin():
    # Collect coins
    item = hero.findNearestItem()
    if item:
        hero.moveXY(item.pos.x, item.pos.y)
    pass
    
def heroAttack():
    fang = hero.findNearest(hero.findByType("fangrider",hero.findEnemies()))
    # Your hero should attack fang riders that cross the minefield.
    hero.attack(fang)
    pass
    
while True:
    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()

put all this part in an if statement checking if the friend exists

also take care of this

Edit: you forgot the parenthesis in this:

1 Like

wdym?
I defined fang as Hero.findNearest(hero.FindByType("fangrider",enemies))

you did, but you didn’t check if it exists nor if it crossed the minefields

But I know that they exist because they crossed over.

Did you solve the level?

Yes I changed the stuff you told me to (other than the fang bit) and I just had to submit it; Thanks!

1 Like

Anytime ( 20 chars )

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