[SOLVED]Reaping fire, don't know what to do(python)

So I’m not really sure what’s happening on this level. here’s the link and my code. :smile:
~Andrew

# 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"
    elif enemy.type == "fangrider":
        return "fight-back"
        # Otherwise, return "collect-coins"
    else:
        return "collect-coins"
        
def commandAttack():
    # Command your griffin riders to attack ogres.
    enemy = hero.findNearestEnemy()
    friends = hero.findFriends()
    
    for friend in friends:
        
        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.
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
    pass
    
while True:
    pickUpCoin()
    commandAttack()
    strategy = chooseStrategy()
    # Call a function, depending on what the current strategy is.
    hero.strategy
    heroAttack
1 Like

So, @CocoCharlie there are a couple issues with your code and strategy. First one that I see is this:

It actually says in the comment right beneath to check if the fangrider is on your side of the mines :upside_down_face:

Next issue is this:

It also says in a comment, (this time right above it) to only attack fangriders that cross the minefield.

Last issue that I see is this one:

What you should do here should look a little more like this:

if strategy == "griffin-rider":
        (Summon your griffin rider)
    if strategy == "fight-back":
        (Call your attack function)
    if strategy == "collect-coins":
        (Call your coin collection function)

Hope this helps!
-Grzmot

3 Likes

Here’s my now code. I have to get offline now though.

# 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.findNearestEnemy()
    fangrider = enemy.type == "fangrider"
    # 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"
    elif fangrider.pos.x < 35:
        return "fight-back"
        # Otherwise, return "collect-coins"
    else:
        return "collect-coins"
        
def commandAttack():
    # Command your griffin riders to attack ogres.
    enemy = hero.findNearestEnemy()
    friends = hero.findFriends()
    
    for friend in friends:
        
        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.
    fangrider = enemy.type == "fangrider"
    fangrider2 = fangrider.pos.x < 35
    if fangrider2:
        hero.attack(fangrider2)
    pass
    
while True:
    strategy = chooseStrategy()
    # 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()
1 Like

I think that you need delete this part:

And then change this part:

And just have something like:

if enemy.type is "fangrider" and enemy.pos.x < 38:

(Combine the 2 lines into 1)

Also, you might need to change this part:

Try changing the enemy = hero.findNearestEnemy() to
enemy = friend.findNearestEnemy() and put it inside the loop where you iterate through your friends so each friend finds an enemy.

Another thing you need to change is this part:

What I would suggest doing is checking to see the fangrider’s x position and to see if it exists in 1 line so it is simplified which will make it easier to find mistakes. It would look something like this:

enemy = hero.findNearest(hero.findEnemies())
if enemy and enemy.pos.x < 38:
        hero.attack(enemy)

The last issue I see is this part:

What worked for me was adding a pickUpCoin() and a commandAttack() before you choose your strategy because if you don’t (at least for me) my hero actually kept stopping which kept him from gathering enough gold, so I failed. Sorry for writing so much, but I hope it all helps!
-Grzmot

2 Likes

@CocoCharlie have you beaten the level yet?
-Grzmot

Sry, I still have scool to do. haven’t gotten to it yet. :slightly_smiling_face:

Oh okay, no worries, I just saw that you were online so I was wondering if you had solved it yet.
-Grzmot

2 Likes

Ok, this aint working. It’s working a little better though. Thanks for that long and tedious explanation btw @Grzmot

 # The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.
def chooseStrategy():
    # 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"
    friends = hero.findFriends()
    for friend in friends:
        enemy = friend.findNearestEnemy()
        if enemy:
            if enemy.type is "fangrider" and enemy.pos.x < 38:
                return "fight-back"
                # Otherwise, return "collect-coins"
        else:
            return "collect-coins"
        
def commandAttack():
    # Command your griffin riders to attack ogres.
    enemy = hero.findNearestEnemy()
    friends = hero.findFriends()
    for friend in friends:
        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.
    enemy = hero.findNearest(hero.findEnemies())
    
    if enemy and enemy.pos.x < 38:
        hero.attack(enemy)
    pass
    
while True:
    pickUpCoin()
    commandAttack()
    strategy = chooseStrategy()
    # 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()

Um, @Lydia_Song can you help? I need to finish this level, and I think you’re online.

Just find the nearest fangrider (fangrider’s type is “fangrider”) and check if there is a fangrider and if the fangrider’s pos.x is less than 36

Check if there is a item, and use hero.move(item.pos)

Check if there is an enemy, and if the hero.distanceTo(enemy) is less than 30 and if the enemy.pos.x is less than 38

Delete this in the while True loop
Lydia

OK, still not working…

# The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.
def chooseStrategy():
    # 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"
    friends = hero.findFriends()
    for friend in friends:
        enemy = friend.findNearestEnemy()
        if enemy:
            if enemy.type is "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.
    enemy = hero.findNearestEnemy()
    friends = hero.findFriends()
    for friend in friends:
        hero.command(friend, "attack", enemy)
    pass
def pickUpCoin():
    # Collect coins
    item = hero.findNearestItem()
    if item:
        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())
    distance = hero.distanceTo(enemy)
    if enemy and enemy.pos.x < 38 and distance < 30:
        hero.attack(enemy)
    pass
    
while True:
    commandAttack()
    strategy = chooseStrategy()
    # 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 should be just defining the fangrider as fangrider = hero.findNearest(hero.findByType("fangrider")
And then checking if there is a fangrider and if the fangrider’s pos.x is less than 36
If so, return “fight-back”

Change this to hero.move(item.pos) so you can command your friends too
Lydia

Ok, now it’s finding a colon that it says shouldn’t be there. In the if statement of the fangrider type.

# The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.
def chooseStrategy():
    # 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"
    friends = hero.findFriends()
    for friend in friends:
        enemy = friend.findNearestEnemy()
        if enemy:
            fangrider = hero.findNearest(hero.findByType("fangrider")
            if fangrider and fangrider.pos.x < 36:
                return "fight-back"
                # Otherwise, return "collect-coins"
        else:
            return "collect-coins"
        
def commandAttack():
    # Command your griffin riders to attack ogres.
    enemy = hero.findNearestEnemy()
    friends = hero.findFriends()
    for friend in friends:
        hero.command(friend, "attack", enemy)
    pass
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.
    enemy = hero.findNearest(hero.findEnemies())
    distance = hero.distanceTo(enemy)
    if enemy and enemy.pos.x < 38 and distance < 30:
        hero.attack(enemy)
    pass
    
while True:
    commandAttack()
    strategy = chooseStrategy()
    # 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()

Please read this carefully
Lydia

Aw man, I have to get offline and go to Tae Kwon Do. I’ll get back to it later.
~Andrew

3 Likes

I’m getting an error. My new code:

# The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.
def chooseStrategy():
    # 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"
    enemy = friend.findNearestEnemy()
    if enemy:
        fangrider = hero.findNearest(hero.findByType("fangrider")
        if fangrider and fangrider.pos.x < 36:
            return "fight-back"
            # Otherwise, return "collect-coins"
        else:
            return "collect-coins"
        
def commandAttack():
    # Command your griffin riders to attack ogres.
    enemy = hero.findNearestEnemy()
    friends = hero.findFriends()
    for friend in friends:
        hero.command(friend, "attack", enemy)
    pass
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.
    enemy = hero.findNearest(hero.findEnemies())
    distance = hero.distanceTo(enemy)
    if enemy and enemy.pos.x < 38 and distance < 30:
        hero.attack(enemy)
    pass

What is that error it is important?

Yeah. I can’t move.

this is the problem. Replace 36 with 25

There’s still an error. That wouldn’t change the error