# Reaping fire help 2

**URL:** <https://discourse.codecombat.com/t/reaping-fire-help-2/16513>\
**Category:** Uncategorized\
**Created:** [November 21, 2018, 3:42pm UTC](https://discourse.codecombat.com/t/reaping-fire-help-2/16513 "2018-11-21T15:42:35Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mratranslate](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@mratranslate](https://discourse.codecombat.com/u/mratranslate)\
**Post date:** [November 21, 2018, 3:42pm UTC](https://discourse.codecombat.com/t/reaping-fire-help-2/16513/1 "2018-11-21T15:42:35Z")

</div>

```python
# 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"
    if enemy:
        for enemy in enemies:
            if enemy.type == "fangrider":
                return "fight-back"
    # Otherwise, return "collect-coins"
    else:
        return "collect-coins"

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

```

My griffin riders don’t attack for some reason? Tried a few variations but can’t get them to shift?!

---

<div class="post-metadata">

**Author:** ![SuperSmacker](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/supersmacker/32/8385_2.png) [@SuperSmacker](https://discourse.codecombat.com/u/SuperSmacker)\
**Post date:** [November 21, 2018, 4:56pm UTC](https://discourse.codecombat.com/t/reaping-fire-help-2/16513/2 "2018-11-21T16:56:04Z")

</div>

for commandAttack() u should use a for loop

---

<div class="post-metadata">

**Author:** ![mratranslate](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@mratranslate](https://discourse.codecombat.com/u/mratranslate)\
**Post date:** [November 22, 2018, 2:46pm UTC](https://discourse.codecombat.com/t/reaping-fire-help-2/16513/4 "2018-11-22T14:46:26Z")

</div>

```python
# 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"
    if enemy:
        for enemy in enemies:
            if enemy.type == "fangrider":
                return "fight-back"
    # Otherwise, return "collect-coins"
    else:
        return "collect-coins"

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

```

I have a for loop in the def now but still doesn’t work. Sorry, not sure what you meant?

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [November 22, 2018, 3:07pm UTC](https://discourse.codecombat.com/t/reaping-fire-help-2/16513/5 "2018-11-22T15:07:39Z")

</div>

You’ve got the for friend in friends right but you don’t also need for enemy in enemies inside that.  
🦁

---

<div class="post-metadata">

**Author:** ![mratranslate](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@mratranslate](https://discourse.codecombat.com/u/mratranslate)\
**Post date:** [November 22, 2018, 3:23pm UTC](https://discourse.codecombat.com/t/reaping-fire-help-2/16513/6 "2018-11-22T15:23:52Z")

</div>

```python
# 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"
    if enemy:
        for enemy in enemies:
            if enemy.type == "fangrider":
                return "fight-back"
    # Otherwise, return "collect-coins"
    else:
        return "collect-coins"

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

```

Took that out but result is the same, nothing moves…

---

<div class="post-metadata">

**Author:** ![Gamestack](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@Gamestack](https://discourse.codecombat.com/u/Gamestack)\
**Post date:** [November 22, 2018, 4:36pm UTC](https://discourse.codecombat.com/t/reaping-fire-help-2/16513/7 "2018-11-22T16:36:03Z")

</div>

😃😃😃😃

---

<div class="post-metadata">

**Author:** ![Gamestack](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@Gamestack](https://discourse.codecombat.com/u/Gamestack)\
**Post date:** [November 22, 2018, 4:42pm UTC](https://discourse.codecombat.com/t/reaping-fire-help-2/16513/8 "2018-11-22T16:42:31Z")

</div>

@mratranslate

> [@mratranslate](#):
>
> # Call a function, depending on what the current strategy is.

I don’t think you did this 😃

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [November 22, 2018, 5:48pm UTC](https://discourse.codecombat.com/t/reaping-fire-help-2/16513/9 "2018-11-22T17:48:38Z")

</div>

```python
def chooseStrategy():
    enemies = hero.findEnemies() # array of units
    # code 
    if enemy: # single enemy -where you define it?
    # code

```

You have stacking of ifs. What’s the real strategy if you select all them simultaneously?

```python
while True:
    strategy = chooseStrategy()
    if strategy == "griffin-rider": # code
    if strategy == "fight-back": # code
    if strategy == "collect-coins": # code

```

I succeeded to finish the level with bonuses following the logic of your program but I get rid of all code related to “fight-back”: and redesigned pickUpCoin()

```python
def pickUpCoin():
    # Collect coins
    items = hero.findItems()
    for item in items:
        hero.moveXY(item.pos.x, item.pos.y)
    pass

```

You are chasing coins dispersed miles away ( items isn’t an ordered array). Make it simple. Find the nearest coin and go for it with move and not with moveXY.

---

<div class="post-metadata">

**Author:** ![mratranslate](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@mratranslate](https://discourse.codecombat.com/u/mratranslate)\
**Post date:** [November 23, 2018, 2:24pm UTC](https://discourse.codecombat.com/t/reaping-fire-help-2/16513/11 "2018-11-23T14:24:43Z")

</div>

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

def chooseStrategy():
    enemy = hero.findNearestEnemy()
    # 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:
        if enemy and enemy.pos.x < 70:
            return "fight-back"
    # Otherwise, return "collect-coins"
    else:
        return "collect-coins"

def commandAttack():
    # Command your griffin riders to attack ogres.
    friends = hero.findByType("griffin-rider")
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type != "fangrider":
        for friend in friends:
            if enemy:
                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.
    enemies = hero.findEnemies()
    for enemy in enemies:
        if enemy and enemy.pos.x < 70:
            hero.attack(enemy)
    pass
    
while True:
    commandAttack()
    
    strategy = chooseStrategy()
    if strategy == "griffin-rider":
        hero.summon("griffin-rider")
    if strategy == "fight-back":
        heroAttack()
    if strategy == "collect-coins":
        pickUpCoin()
    # Call a function, depending on what the current strategy is.
    hazards = hero.findHazards()
    if len(hazards) == 0:
        break
        while True:
            hero.attack(enemy)

```

This is an interesting level! Move doesn’t work for me as it says it is a protected property so had to stick with XY. Redesigned my code but it still didn’t work as I didn’t seem to have enough griffin riders to combat ogres. I have ended up cheating for the time being by extending sennick’s rifle engagement range which enables me to complete the level but without bonus. As soon as the minefield blows he stops attacking. The proper way I presume is to generate more griffin riders but as to how to do this I’m not sure!

---

<div class="post-metadata">

**Author:** ![MunkeyShynes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munkeyshynes/32/9277_2.png) [@MunkeyShynes](https://discourse.codecombat.com/u/MunkeyShynes)\
**Post date:** [November 23, 2018, 2:30pm UTC](https://discourse.codecombat.com/t/reaping-fire-help-2/16513/12 "2018-11-23T14:30:54Z")

</div>

Don’t get discouraged. I spent about two weeks on this level before I finally got the 60 second bonus. I changed heroes several times and redesigned my entire strategy several times. I finally used Nalfar and his “haste” method to create enough griffin-riders. Just keep tweaking your code 'till you finally nail it.

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [November 23, 2018, 8:34pm UTC](https://discourse.codecombat.com/t/reaping-fire-help-2/16513/13 "2018-11-23T20:34:16Z")

</div>

Your griffin riders wait near the hero until the enemies appear. Move them somewhere in the middle of the screen .( I forgot to tell you that)

```python
def commandAttack():
# code
            if enemy:
                hero.command(friend, "attack", enemy)
            else:
               # move friends to the right ( I didn't test where's the best point) 

```

“Move doesn’t work for me as it says it is a protected property”  
Buy the cheapest _move_ boots ( if you haven’t got any) - _Compound Boots_ . _Boots of Jumping_ are slow. Wait to increase your level and gems and buy the best boots - _Boots of Leaping._
