Reaping Fire priority

Hi,

I struggle to understand how to make priority for this level. My griffin riders get attacked by the fangriders and all the walking orc die and the mine field explose after 15 secondes.
I don’t understand how to collect enought gold in order to have my griffinriders survive.
I tried to add peasant to collect more coin but they cling to my hero after few of them collected.
If you have suggestion that would be nice.

# The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.
cpt = 0
def chooseStrategy():
    enemies = hero.findEnemies()
    nearest = hero.findNearestEnemy()
    
    # If you can summon a griffin-rider, return "griffin-rider"
    
    if hero.costOf("peasant") <= hero.gold and cpt < 1:
        hero.summon("peasant")
        cpt += 1
        return "peasant"
    elif hero.costOf("griffin-rider") <= hero.gold:
        hero.summon("griffin-rider")
        return "griffin-rider"        
    # If there is a fangrider on your side of the mines, return "fight-back"
    elif nearest and nearest.type == "fangrider" and nearest.pos.x < 37:
        return "fight-back"
    # Otherwise, return "collect-coins"
    else:
        return "collect-coins"

def commandAttack():
    # Command your griffin riders to attack ogres.
    griffins = hero.findByType("griffin-rider", hero.findFriends()) 
    for griffin in griffins:
        enemy = griffin.findNearestEnemy()
        if enemy and enemy.type != "fangrider":
            hero.command(griffin, "defend", {"x": 70, "y": 35})
        else:
            hero.command(griffin, "move", {"x": 70, "y": 35})

def peasantPicker():
    # Command your peasant to pick coin:
    peasants = hero.findByType("peasant", hero.findFriends()) 
    for peasant in peasants :
        coin = peasant.findNearestItem()
        if coin:
            hero.command(peasant, "move", coin.pos)
                
                
def pickUpCoin():
    # Collect coins
    coin = hero.findNearestItem()
    if coin:
        hero.moveXY(coin.pos.x, coin.pos.y)
    
def heroAttack():
    # Your hero should attack fang riders that cross the minefield.
    enemies = hero.findByType("fangrider", hero.findEnemies())
    for enemy in enemies:
        if hero.canCast("chain-lightning"):
            hero.cast("chain-lightning", enemy)
        elif hero.isReady("cleave") and hero.distanceTo(enemy) < 10:
            hero.cleave(enemy)
        else:
            hero.attack(enemy)


while True:
    commandAttack()
    strategy = chooseStrategy()
    peasantPicker()
    # Call a function, depending on what the current strategy is.
    #hero.say(strategy)
    if strategy == "griffin-rider":
        commandAttack()
        #hero.say("griffin-rider")
    elif strategy == "fight-back":
        heroAttack()
    else:
        pickUpCoin()


Hi Nico,

I tried your code and it didn’t work, so I made it simpler. I did a couple of things:

  • In the commandAttack function, inside the for loop, I just found the griffin’s nearest enemy, and then commanded the griffin to attack this.
  • I got rid of your peasants (sorry!) - they slow down the number of griffin-riders you make.

If that isn’t enough, then do you have the Ring of Speed for your hero, and some of the boots with the increased speed (eg Compound boots)? I’m playing with one of the free heros, but these make a big difference.

Post again if you need more help.

Jenny

Hi Niko!
You can get personalized help posting your level session Id in separate post.
How to do it: [SOLVED]Javascript: Aggressive Mimicry Help - #12 by xython
when you succeed it’s better to delete the post.

I ugly patched your code and passed the level several times with or without bonus pasting the code into several sessions taken from the leader board.
Corrections i’ve made:

 def chooseStrategy():      
    if hero.costOf("peasant") <= hero.gold and len(hero.built) == 1 and cpt < 1:
        #  len(hero.built) == 1 - the peasant will be built after one griffin
        # if that doesn't work try  len(hero.built) ==  2
        # ..... your code
 
def pickUpCoin():
    coin = hero.findNearestItem()
    if coin:
        # hero.moveXY(coin.pos.x, coin.pos.y)
           hero.move(coin.pos)
        # Jenny suggested that in her post

def heroAttack():
    enemies = hero.findByType("fangrider", hero.findEnemies())
    for enemy in enemies:
        if enemy.pos.x < 37: # insert this line and reformat the rest
            if hero.canCast("chain-lightning"):
                hero.cast("chain-lightning", enemy)
            # ... your code

Hi Jenny ! This is a bit late but the song was for you and all women here :slight_smile:

1 Like
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 and enemy.type == "fangrider" and enemy.pos.x < 38:
        return "fight-back"
    # Otherwise, return "collect-coins"
    else:
        return "collect"

def command():
    # Command your griffin riders to attack ogres.
    friends = hero.findByType("griffin-rider")
    if friends:
        for friend in hero.findByType("griffin-rider"):
            enemy = friend.findNearestEnemy()
            if enemy:
                hero.command(friend, "attack", enemy)
    pass
def collect():
    # Collect coins
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)
    pass
def attack():
    # Your hero should attack fang riders that cross the minefield.
    fang = hero.findNearestEnemy()
    if fang:
        hero.attack(fang)
    pass
while True:
    command()
    strategy = chooseStrategy()
    # Call a function, depending on what the current strategy is.
    if strategy == "griffin-rider":
        hero.summon("griffin-rider")
    elif strategy == "fight-back":
        attack()
    else:
        collect()

Why is enemy undefined?

EDIT: D’oh I’m an idiot, and was replying to @Oliver_Davidson, when he’s asking a question to help @Nico. Maybe ignore this post!

Because you haven’t defined enemy in the chooseStrategy function, so the computer doesn’t know what to do with this line!

Jenny

Thanks for the suggestion. The problem is that the fangrider start to attack the griffin rider at one point kill them and move on to seek my hero…

@Nico, that happens to me as well. I usually die before the end, but having held the enemies off for long enough to pass the level and get the bonus.

If you want more help, can you post your updated code and a screenshot of your equipment?

Jenny