Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Reaping Fire HELP Please

Hi I have been trying to get this and I was looking and looking on if my code had something wrong but I don’t know.

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

def chooseStrategy():
    enemies = hero.findEnemies()
    enemy = self.findNearest(enemies)
    
    # If you can summon a griffin-rider, return "griffin-rider"
    if self.gold > self.costOf("griffin-rider") and enemy:
        return "griffin-rider"
    # If there is a fangrider on your side of the mines, return "fight-back"
    elif enemy and enemy.type == "fagrider" and self.distance (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 self.findByType("griffin-rider"):
        if griffin:
            enemy = griffin.findNearestEnemy
            if enemy:
                self.command(griffin,"attack", enemy)
    pass
    
def pickUpCoin():
    # Collect coins
    coin = self. findNearest(self.findItems())
    if coin:
        hero.move(coin.pos)
    pass
    
def heroAttack():
    # Your hero should attack fang riders that cross the minefield.
    enemy = self.findNearest(self.findEnemies())
    if enemy and self.distanceTo(enemy) < 30:
        self.attack(enemy)
    pass
    
while True:
    commandAttack()
    strategy = chooseStrategy()
    # Call a function, depending on what the current strategy is.
    if strategy == "griffin-rider":
        self.summon("griffin-rider")
    if strategy == "fight-back":
        commandAttack()
    if strategy == "collect-coins":
        pickUpCoin()

Thank you so much to anyone who can help.

“fagrider” should be fangrider, for a start. Also, you should be using hero.[function], vs self.[function] (like hero.findNearest(hero.findItems()))

Hi @hieveryone2, please only ask for help in one location, asking for it in two will not get you help any faster or from more people.
Could you read my post in the other topic (Help with Reaping Fire), then stick to this one,
Thanks
Danny

1 Like

is there any reason why this code is incorrect?

# 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"
    for enemy in enemies:
        if enemy and enemy.type is "fangrider":
            return "fight-back"
        else:
            return "collect-coins"
    # If there is a fangrider on your side of the mines, return "fight-back"
    # Otherwise, return "collect-coins"

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

Thank you so much to anyone who can help.

Can anyone please help me if they see this.

# 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"
    for enemy in enemies:
        if enemy and enemy.type is "fangrider":
            return "fight-back"
        else:
            return "collect-coins"
    # If there is a fangrider on your side of the mines, return "fight-back"
    # Otherwise, return "collect-coins"

def commandAttack():
    # Command your griffin riders to attack ogres.
    friend = hero.findNearest(hero.findFriends())
    enemy = hero.findNearest(hero.findEnemies())
    friends = hero.findFriends()
    enemies = hero.findEnemies()
    for enemy in enemies:
        for friend in friends:
            if friend.type == "griffin-rider":
                if enemy.type != "fan-grider":
                    hero.command(friend, "attack", enemy)
    pass

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

Please If anyone can help me. That would be greatly appreciated.

Hi,
Ok, let’s go through it bit by bit.
Firstly in the chooseStrategy bit,

  1. When you return ‘griffin-rider’ you don’t need to summon a griffin rider there, you can summon it in the while true loop, just return ‘griffin-rider’. You’ve got command Attack in the while true loop but you’ve already called that further up.
  2. You don’t need to loop through enemies, just find the nearest one and do the same checks, plus what it says in the comment:

Otherwise you risk setting of the mines.

CommandAttack function.

  1. you’re looping through enemies and friends, that’s not necessary. Just loop through friends as you did in earlier levels. Plus there’s a typo: if enemy.type != “fan-grider”: It should be “fangrider” no hyphen. I think it’s a good idea to not tell them to attack the fangriders, but, if your code works as you intended, they just sit there. Have a think about why that is.

In the while true loop remember to summon a griffin rider in the if strategy == “griffin-rider”.
Danny

Thank you so much for all the help!!!
I just wanted to ask another question. It keeps on saying that everything is correct and I keep looking over and looking at your post to help me, but I just don’t know

# 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"):
        enemy = hero.findNearestEnemy()
        return "griffin-rider"
        if enemy and enemy.type == "fangrider":
            return "fight-back"
        else:
            return "collect-coins"
    # If there is a fangrider on your side of the mines, return "fight-back"
    # Otherwise, return "collect-coins"

def commandAttack():
    # Command your griffin riders to attack ogres.
    friend = hero.findNearest(hero.findFriends())
    enemy = hero.findNearest(hero.findEnemies())
    friends = hero.findFriends()
    enemies = hero.findEnemies()
    for friend in friends:
        if friend.type == "griffin-rider":
            pass

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


I can see that you’re missing any attack code for the griffin riders, you need to tell them to attack the enemy.
Danny

Everytime that I add that code it is still incomplete even though it says that all my code is correct.

Please could you post your code with that included, along with a screenshot.
Thanks

def chooseStrategy():
    enemies = hero.findEnemies()
    # If you can summon a griffin-rider, return "griffin-rider"
    if hero.gold >= hero.costOf("griffin-rider"):
        enemy = hero.findNearestEnemy()
        return "griffin-rider"
        if enemy and enemy.type == "fangrider":
            
            return "fight-back"
        else:
            return "collect-coins"
    # If there is a fangrider on your side of the mines, return "fight-back"
    # Otherwise, return "collect-coins"

def commandAttack():
    # Command your griffin riders to attack ogres.
    friend = hero.findNearest(hero.findFriends())
    enemy = hero.findNearest(hero.findEnemies())
    friends = hero.findFriends()
    enemies = hero.findEnemies()
    for friend in friends:
        if friend.type == "griffin-rider":
            
            pass

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


THis is what it is looking like. Also thank you so much for all of your help!

Hi,
You still haven’t put any code to command the griffin riders. If you don’t put any in, it won’t work. You need them to attack the ogres or you’ve pretty much lost.
Danny

1 Like

You’re going to need to fix the heroAttack function, since leaving it like that will make your hero move to the mines and set it off. find the x position of the mines closest to you, and add

posX = enemy.pos.x

i also recommend that you use findByType and findNearest to target fangriders only

type = hero.findByType("fangrider")
enemy = hero.findNearest(type)

and after defining the variables, your if statement should look like this

if enemy && posX < 35 :  // change the number 35 to the x position of the mines closest to you.
hero.attack(enemy)
pass

as for your griffins, command them to attack right after you summoned them.

P.S. I recommend you to use a different strategy when the time is already over 30 - 35 seconds, as the ogres will get stronger and will eventually set off the mines. But since it’s already over 30 seconds the clear condition is still check.

Hope you succeed
Riley

1 Like

Thank you so much!!! I did succeed.

Glad to help, any luck on the bonus?

I got the bonus!! Yes.

Good on you, careful though, the few levels after this can get very difficult