Reaping fire help 2

# 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:
        for enemy in enemies:
            if enemy.type == "fangrider":
                return "fight-back"
    # Otherwise, return "collect-coins"
    else:
        return "collect-coins"

def commandAttack():
    # Command your griffin riders to attack ogres.
    griffin = hero.findByType("griffin-rider")
    if griffin:
        enemy = hero.findNearestEnemy()
        if enemy:
            hero.command(griffin, "attack", enemy)
    pass
    
def pickUpCoin():
    # Collect coins
    items = hero.findItems()
    for item in items:
        hero.moveXY(item.pos.x, item.pos.y)
    pass
    
def heroAttack():
    # Your hero should attack fang riders that cross the minefield.
    enemies = hero.findEnemies()
    for enemy in enemies:
        if enemy.type == "fangrider" and enemy.pos.x < 38:
            hero.attack(enemy)
    pass
    
while True:
    commandAttack()
    strategy = chooseStrategy()
    if strategy == "griffin-rider":
        hero.summon("griffin-rider")
    if strategy == "fight-back":
        heroAttack()
    if strategy == "collect-coins":
        pickUpCoin()
    # Call a function, depending on what the current strategy is.
    

My griffin riders don’t attack for some reason? Tried a few variations but can’t get them to shift?!

for commandAttack() u should use a for loop

# 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:
        for enemy in enemies:
            if enemy.type == "fangrider":
                return "fight-back"
    # Otherwise, return "collect-coins"
    else:
        return "collect-coins"

def commandAttack():
    # Command your griffin riders to attack ogres.
    friends = hero.findByType("griffin-rider")
    enemies = hero.findEnemies()
    for friend in friends:
        for enemy in enemies:
            if enemy:
                hero.command(friend, "attack", enemy)
    pass
    
def pickUpCoin():
    # Collect coins
    items = hero.findItems()
    for item in items:
        hero.moveXY(item.pos.x, item.pos.y)
    pass
    
def heroAttack():
    # Your hero should attack fang riders that cross the minefield.
    enemies = hero.findEnemies()
    for enemy in enemies:
        if enemy.type == "fangrider" and enemy.pos.x < 38:
            hero.attack(enemy)
    pass
    
while True:
    commandAttack()
    strategy = chooseStrategy()
    if strategy == "griffin-rider":
        hero.summon("griffin-rider")
    if strategy == "fight-back":
        heroAttack()
    if strategy == "collect-coins":
        pickUpCoin()
    # Call a function, depending on what the current strategy is.
    
    

I have a for loop in the def now but still doesn’t work. Sorry, not sure what you meant?

You’ve got the for friend in friends right but you don’t also need for enemy in enemies inside that.
:lion:

# 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:
        for enemy in enemies:
            if enemy.type == "fangrider":
                return "fight-back"
    # Otherwise, return "collect-coins"
    else:
        return "collect-coins"

def commandAttack():
    # Command your griffin riders to attack ogres.
    friends = hero.findByType("griffin-rider")
    enemy = hero.findNearestEnemy()
    for friend in friends:
        if enemy:
            hero.command(friend, "attack", enemy)
    pass
    
def pickUpCoin():
    # Collect coins
    items = hero.findItems()
    for item in items:
        hero.moveXY(item.pos.x, item.pos.y)
    pass
    
def heroAttack():
    # Your hero should attack fang riders that cross the minefield.
    enemies = hero.findEnemies()
    for enemy in enemies:
        if enemy.type == "fangrider" and enemy.pos.x < 38:
            hero.attack(enemy)
    pass
    
while True:
    commandAttack()
    strategy = chooseStrategy()
    if strategy == "griffin-rider":
        hero.summon("griffin-rider")
    if strategy == "fight-back":
        heroAttack()
    if strategy == "collect-coins":
        pickUpCoin()
    # Call a function, depending on what the current strategy is.
    

Took that out but result is the same, nothing moves…

:smiley::smiley::smiley::smiley:

@mratranslate

I don’t think you did this :smiley:

def chooseStrategy():
    enemies = hero.findEnemies() # array of units
    # code 
    if enemy: # single enemy -where you define it?
    # code

You have stacking of ifs. What’s the real strategy if you select all them simultaneously?

while True:
    strategy = chooseStrategy()
    if strategy == "griffin-rider": # code
    if strategy == "fight-back":  # code
    if strategy == "collect-coins": # code

I succeeded to finish the level with bonuses following the logic of your program but I get rid of all code related to “fight-back”: and redesigned pickUpCoin()

def pickUpCoin():
    # Collect coins
    items = hero.findItems()
    for item in items:
        hero.moveXY(item.pos.x, item.pos.y)
    pass

You are chasing coins dispersed miles away ( items isn’t an ordered array). Make it simple. Find the nearest coin and go for it with move and not with moveXY.

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

def chooseStrategy():
    enemy = hero.findNearestEnemy()
    # 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:
        if enemy and enemy.pos.x < 70:
            return "fight-back"
    # Otherwise, return "collect-coins"
    else:
        return "collect-coins"

def commandAttack():
    # Command your griffin riders to attack ogres.
    friends = hero.findByType("griffin-rider")
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type != "fangrider":
        for friend in friends:
            if enemy:
                hero.command(friend, "attack", enemy)
    pass
    
def pickUpCoin():
    # Collect coins
    item = hero.findNearestItem()
    hero.moveXY(item.pos.x, item.pos.y)
    
    pass
    
def heroAttack():
    # Your hero should attack fang riders that cross the minefield.
    enemies = hero.findEnemies()
    for enemy in enemies:
        if enemy and enemy.pos.x < 70:
            hero.attack(enemy)
    pass
    
while True:
    commandAttack()
    
    strategy = chooseStrategy()
    if strategy == "griffin-rider":
        hero.summon("griffin-rider")
    if strategy == "fight-back":
        heroAttack()
    if strategy == "collect-coins":
        pickUpCoin()
    # Call a function, depending on what the current strategy is.
    hazards = hero.findHazards()
    if len(hazards) == 0:
        break
        while True:
            hero.attack(enemy)

This is an interesting level! Move doesn’t work for me as it says it is a protected property so had to stick with XY. Redesigned my code but it still didn’t work as I didn’t seem to have enough griffin riders to combat ogres. I have ended up cheating for the time being by extending sennick’s rifle engagement range which enables me to complete the level but without bonus. As soon as the minefield blows he stops attacking. The proper way I presume is to generate more griffin riders but as to how to do this I’m not sure!

Don’t get discouraged. I spent about two weeks on this level before I finally got the 60 second bonus. I changed heroes several times and redesigned my entire strategy several times. I finally used Nalfar and his “haste” method to create enough griffin-riders. Just keep tweaking your code 'till you finally nail it.

1 Like

Your griffin riders wait near the hero until the enemies appear. Move them somewhere in the middle of the screen .( I forgot to tell you that)

def commandAttack():
# code
            if enemy:
                hero.command(friend, "attack", enemy)
            else:
               # move friends to the right ( I didn't test where's  the best point) 

“Move doesn’t work for me as it says it is a protected property”
Buy the cheapest move boots ( if you haven’t got any) - Compound Boots . Boots of Jumping are slow. Wait to increase your level and gems and buy the best boots - Boots of Leaping.