[SOLVED] Fire reaping Help

def chooseStrategy():
enemies = hero.findEnemies()
enemy = hero.findNearest(enemies)
# 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”
elif enemy and enemy.type == “fangrider” and hero.distanceTo(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 hero.findByType(“griffin-rider”):
if griffin:
enemy = griffin.findNearestEnemy()
if enemy:
hero.command(griffin, “attack”, enemy)

def pickUpCoin():
# Collect coins
while True:
item = hero.findNearestItem()
if item:
hero.move(item.pos)
pass

def heroAttack():
# Your hero should attack fang riders that cross the minefield.
target = hero.findNearest(hero.findByType(“fangrider”))
if target:
if hero.distanceTo(target) < 20:
hero.move(targetPos)
else:
hero.attack(target)
while True:
commandAttack()
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()
if you have a code that works please post it!

Hi. Could you format your code like this so we can help?

I don’t know how but can you help me figure out what the code is suposed to be like?

def chooseStrategy():
      enemies = hero.findEnemies()
      enemy = hero.findNearest(enemies)
      if hero.gold >= hero.costOf(“griffin-rider”):
            hero.summon(“griffin-rider”)
            return “griffin-rider”
      elif enemy and enemy.type == “fangrider” and hero.distanceTo(enemy) < 30:
            return “fight-back”
      else:
            return “collect-coins”

def commandAttack():
        for griffin in hero.findByType(“griffin-rider”):
         if griffin:
               enemy = griffin.findNearestEnemy()
               if enemy:
                      hero.command(griffin, “attack”, enemy)

def pickUpCoin():
     
            item = hero.findNearestItem()
            if item:
                hero.move(item.pos)
                pass

def heroAttack():
         target = hero.findNearest(hero.findByType(“fangrider”))
        if target:
                if hero.distanceTo(target) < 20:
                        hero.move(target.pos)
                else:
                        hero.attack(target)


while True:
   strategy = chooseStrategy()
   if strategy == “griffin-rider”:
       commandAttack()
   if strategy == “fight-back”:
       heroAttack()
   if strategy == “collect-coins”:
       pickUpCoin()

Can you describe the error that you are facing?

there is no error. Its just that I can’t keep all the enemies from blowing up the mines!

You should not use a while True in the pickUpCoin function

where is it? i cant seem to find it

That will run forever and the rest of the code won’t work how it is supposed to

1 Like

it is now saying that target pos is not defined

Here it is. Remove the while True loop.

I fixed that. But did you see my new post?

You should write

target.pos

instead of

targetPos

Here is the mistake.

Okay well here goes nothing!

still not working!!!

Can you look through my code on the level and see if you can figure out the correct code. Then just send me it and i think i can get through

Try to put 4 spaces on each instruction in a loop, so I can see the code better.

i DONT UNDERstand. what?

Here you should put

and enemy.pos.y < 17: