Help on level reaping fire{SOLVED}

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

def commandAttack():
    # Command your griffin riders to attack ogres.
    for griffin in self.findByType("griffin-rider"):
        if griffin:
            enemy = griffin.findNearest(griffin.findEnemies)
            if enemy:
                self.command(griffin, "attack", enemy)

def pickUpCoin():
    # Collect coins
    coin = self.findNearest(self.findItems())
    if coin:
        self.move(coin.pos)

def heroAttack():
    # Your hero should attack fang riders that cross the minefield.
    enemy = self.findNearest(self.findEnemies())
    if enemy and self.distanceTo(enemy) < 30:
        if self.canCast("fear", enemy):
            self.cast("fear", enemy)
            if self.canCast("invisibility", self):
                self.cast("invisibility", self)
        elif self.canCast("drain-life", enemy):
            self.cast("drain-life", enemy)
            if self.canCast("invisibility", self):
                self.cast("invisibility", self)
        elif self.canCast("invisibility", self):
                self.cast("invisibility", self)
loop:
    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":
        heroAttack()
    if strategy == "collect-coins":
        pickUpCoin()

When I run this code it works fine until enemies appear, then my hero freezes and my griffins do nothing. What is wrong? Any help is greatly appreciated (even if it doesn’t work :yum:).

You forgot a pair of parentheses at the end of findEnemies in enemy = griffin.findNearest(griffin.findEnemies).

1 Like

Thank you so much. Can’t believe I didn’t see that. That solved the griffin problem but my hero still freezes when the enemy shows up. Any suggestions?

Try making the enemy check individual. Here’s what I mean:

if enemy:
    # Put rest of your statements here

See if that helps.

I’m not sure I understand. Do you mean this part:

elif enemy:
            if enemy.type == "fangrider" and self.distanceTo(enemy) < 30:
                return "fight-back

because i’ve already tried if instead of elif and that doesn’t work.

Sorry, I should have made myself more clear.

Make if enemy: a separate block in heroAttack(). After that, put the rest of your statements inside.

Do you mean like this:

if enemy:
        if self.distanceTo(enemy) < 15:

and then all the other stuff in the function, because i’ve already tried that too and it doesnt work. I’m so confused. :confounded: Thanks for you’re help though.

Strange. My code is almost exactly like yours, and worked last time I played this level, but now it doesn’t, with the same eproblem as yours. Hm…

Well, when in doubt, call @nick!

        elif enemy:
            if enemy.type == "fangrider" and self.distanceTo(enemy) < 30:
                return "fight-back"

If there is an enemy but it’s not a fangrider closer than 30m from you, then you will return None from this method and take no action. Try something like:

        elif enemy and enemy.type == 'fangrider' and self.distanceTo(enemy) < 30:
            return "fight-back"

Yes! It finally worked! I can move on! Thank you so much!

Hi i’m totally stuck on this level I tried beating it, but I just can’t. Here is my code:

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

def chooseStrategy():
enemies = self.findEnemies()
enemy = self.findNearest(enemies)
# If you can summon a griffin-rider, return "griffin-rider"
if self.gold >= self.costOf(“griffin-rider”):
self.summon(“griffin-rider”)
# If there is a fangrider on your side of the mines, return "fight-back"
if enemy and self.distanceTo(enemy) < 6:
self.attack(enemy)
# Otherwise, return "collect-coins"
else:
coin = self.findNearest(self.findItems())
if coin:
self.move(coin.pos)
def commandAttack():
friends = self.findFriends()
friend = self.findNearest(friends)
defencePoint = {“x”: 56, “y”: 43}
if friend:
enemies = friend.findEnemies()
enemy = friend.findNearest(enemies)
if enemy and enemy.type is not “fang-rider”:
self.command(friend, “attack”, enemy)
else:
self.command(friend, “move”, defencePoint)

def pickUpCoin():
coin = self.findNearest(self.findItems())
if coin:
self.move(coin.pos)

def heroAttack():
enemies = self.findEnemies()
enemy = self.findNearest(enemies)
if enemy:
if enemy.type is “fang-rider”:
if self.distanceTo(enemy) > 6:
self.attack(enemy)
else:
pickUpCoin()
loop:
commandAttack()
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
heroAttack()
pickUpCoin()

@nick I really need help!!! =<

Your code is almost good, you just need to fix the fight-back part:

if self.distanceTo(enemy) > 6:
self.attack(enemy)

This will not work, since the fang-riders always attack from a range.Use a combination of distance and enemy.pos.x instead.

Use a sorcerer and manablast.

The 60 seconds survival bonus needs very good code or equipment, you might want to save the level and come back latter to get the bonus.

i dont known whats wrong with my code it doesnt say anything is wrong my hero doesnt move to collect gold and he summons one griffin and the griffin doesnt attack any enemies here is my code

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

def commandAttack():
    # Command your griffin riders to attack ogres.
    for griffin in self.findByType("griffin-rider"):
        if griffin:
            enemy = griffin.findNearest(griffin.findEnemies)
            if enemy:
                self.command(griffin, "attack", enemy)

def pickUpCoin():
    # Collect coins
    coin = self.findNearest(self.findItems())
    if coin:
        self.move(coin.pos)


   
   
loop:
    commandAttack()
    strategy = chooseStrategy()
    # Call a function, depending on what the current strategy is.
    if strategy == "griffin-rider":
        self.summon("griffin-rider")
    if strategy == "collect-coins":
        pickUpCoin()

nvm my code is fine now but the enemies get the mines in under 30 seconds

def chooseStrategy():
    enemies = self.findEnemies()
    enemy = self.findNearest(enemies)
    if self.gold > self.costOf("griffin-rider"):
        return "griffin-rider"
    # If you can summon a griffin-rider, return "griffin-rider"
    elif enemy:
        if enemy.type is "fangrider" and self.distanceTo(enemy) < 30:
            return "fight-back"
    # If there is a fangrider on your side of the mines, return "fight-back"
    else:
        return "collect-coins"
    # Otherwise, 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)
    
def pickUpCoin():
    # Collect coins
    coin = self.findNearest(self.findItems())
    if coin:
        self.move(coin.pos)
    
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)
loop:
    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":
        heroAttack()
    if strategy == "collect-coins":
        pickUpCoin()

my hero does stop moving to collect coins and the fang riders still get the mines out or some other enemy

i changed my code in the fangrider part to this

def chooseStrategy():
    enemies = self.findEnemies()
    enemy = self.findNearest(enemies)
    if self.gold > self.costOf("griffin-rider"):
        return "griffin-rider"
    # If you can summon a griffin-rider, return "griffin-rider"
    elif enemy and enemy.type == 'fangrider' and self.distanceTo(enemy) < 30:
            return "fight-back"
    # If there is a fangrider on your side of the mines, return "fight-back"
    else:
        return "collect-coins"
    # Otherwise, 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)
    
def pickUpCoin():
    # Collect coins
    coin = self.findNearest(self.findItems())
    if coin:
        self.move(coin.pos)
    
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)
loop:
    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":
        heroAttack()
    if strategy == "collect-coins":
        pickUpCoin()

now my hero will still collect coins instead of stopping

i beat it so i move on

Yeah, you needed “if enemy”… :slight_smile: