# Reaping fire python, please help

**URL:** <https://discourse.codecombat.com/t/reaping-fire-python-please-help/26374>\
**Category:** Level Help\
**Created:** [January 5, 2021, 2:38pm UTC](https://discourse.codecombat.com/t/reaping-fire-python-please-help/26374 "2021-01-05T14:38:23Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![QinWentian](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/qinwentian/32/17063_2.png) [@QinWentian](https://discourse.codecombat.com/u/QinWentian)\
**Post date:** [January 5, 2021, 2:38pm UTC](https://discourse.codecombat.com/t/reaping-fire-python-please-help/26374/1 "2021-01-05T14:38:24Z")

</div>

Here is my code:

```python
# The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.
enemyIndex = 0
def chooseStrategy():
    enemyyyy = hero.findNearestEnemy()
    
    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"
    while enemyIndex<len(enemies):
        enemy = enemies[enemyIndex]
        if enemy.type == 'fangrider' and hero.distanceTo(enemyyyy):
            return heroAttack()
            
    enemyIndex+=1
     
    # Otherwise, return "collect-coins"
    return pickUpCoin()

def commandAttack():
    # Command your griffin riders to attack ogres.
    hero.summon("griffin-rider")
    enemy = hero.findNearestEnemy()
    
    if enemy:
        soldier = hero.findFriends()
        soldierIndex = 0
        
        
        while soldierIndex < len(soldier):
            soldier = soldiers[soldierIndex]
            hero.command(soldier, "attack", enemy)
            soldierIndex+=1
    
    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.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
    pass
    
while True:
    commandAttack()
    strategy = chooseStrategy()
    # Call a function, depending on what the current strategy is.
    

```

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [January 5, 2021, 2:48pm UTC](https://discourse.codecombat.com/t/reaping-fire-python-please-help/26374/2 "2021-01-05T14:48:07Z")

</div>

> [@QinWentian](#):
>
> `return heroAttack()`

This should be

```python
return "fight-back"

```

Also, what if you can’t return “griffin-rider” or return “fight-back”. Use an else statement with

```python
return "collect-coins"

```

Then in your while true loop, create a variable for chooseStrategy() and check if the variable is equal to a strategy.

---

<div class="post-metadata">

**Author:** ![ZAX155](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/zax155/32/34141_2.png) [@ZAX155](https://discourse.codecombat.com/u/ZAX155)\
**Post date:** [January 5, 2021, 2:48pm UTC](https://discourse.codecombat.com/t/reaping-fire-python-please-help/26374/3 "2021-01-05T14:48:08Z")

</div>

what world is this on

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [January 5, 2021, 2:50pm UTC](https://discourse.codecombat.com/t/reaping-fire-python-please-help/26374/4 "2021-01-05T14:50:50Z")

</div>

It is a level in Cloudrip Mountain.

---

<div class="post-metadata">

**Author:** ![ZAX155](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/zax155/32/34141_2.png) [@ZAX155](https://discourse.codecombat.com/u/ZAX155)\
**Post date:** [January 5, 2021, 2:52pm UTC](https://discourse.codecombat.com/t/reaping-fire-python-please-help/26374/5 "2021-01-05T14:52:17Z")

</div>

oh okay sorry i cannot help then

---

<div class="post-metadata">

**Author:** ![\_Codemaster](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/_codemaster/32/26944_2.png) [@\_Codemaster](https://discourse.codecombat.com/u/_Codemaster)\
**Post date:** [January 5, 2021, 3:26pm UTC](https://discourse.codecombat.com/t/reaping-fire-python-please-help/26374/6 "2021-01-05T15:26:28Z")

</div>

I’d like to note that when I used the strategy they told me to, I failed, so I just collected coins, while griffin riders fought.

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [January 5, 2021, 11:22pm UTC](https://discourse.codecombat.com/t/reaping-fire-python-please-help/26374/7 "2021-01-05T23:22:16Z")

</div>

What’s this for?  
are you supposed to use 4 y’s?

> [@QinWentian](#):
>
> `enemyyyy = hero.findNearestEnemy()`

I noticed it right away. I’m only at the beginning of the mountains, so don’t ask me for more help. 😃  
~Charlie

---

<div class="post-metadata">

**Author:** ![QinWentian](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/qinwentian/32/17063_2.png) [@QinWentian](https://discourse.codecombat.com/u/QinWentian)\
**Post date:** [January 6, 2021, 10:10am UTC](https://discourse.codecombat.com/t/reaping-fire-python-please-help/26374/8 "2021-01-06T10:10:05Z")

</div>

I already had a variable for enemy so enemyyy is a different veriable

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [January 6, 2021, 8:12pm UTC](https://discourse.codecombat.com/t/reaping-fire-python-please-help/26374/9 "2021-01-06T20:12:13Z")

</div>

Ok, so that’s just your personal variable. cool. 🙂

---

<div class="post-metadata">

**Author:** ![ZAX155](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/zax155/32/34141_2.png) [@ZAX155](https://discourse.codecombat.com/u/ZAX155)\
**Post date:** [January 6, 2021, 8:40pm UTC](https://discourse.codecombat.com/t/reaping-fire-python-please-help/26374/10 "2021-01-06T20:40:03Z")

</div>

yep thats correct @CocoCharlie

---

<div class="post-metadata">

**Author:** ![WaWa\_Yang](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/wawa_yang/32/17800_2.png) [@WaWa\_Yang](https://discourse.codecombat.com/u/WaWa_Yang)\
**Post date:** [January 7, 2021, 2:16am UTC](https://discourse.codecombat.com/t/reaping-fire-python-please-help/26374/11 "2021-01-07T02:16:22Z")

</div>

> [@QinWentian](#):
>
> ```python
> while enemyIndex<len(enemies):
> enemy = enemies[enemyIndex]
> if enemy.type == 'fangrider' and hero.distanceTo(enemyyyy):
> return heroAttack()
>             
> enemyIndex+=1
>      
> # Otherwise, return "collect-coins"
> return pickUpCoin()
> 
> ```

_otherwise_  
use else

> [@QinWentian](#):
>
> ```python
> def commandAttack():
> # Command your griffin riders to attack ogres.
> hero.summon("griffin-rider")
> enemy = hero.findNearestEnemy()
>     
> if enemy:
> soldier = hero.findFriends()
> soldierIndex = 0
>         
>         
> while soldierIndex < len(soldier):
> soldier = soldiers[soldierIndex]
> hero.command(soldier, "attack", enemy)
> soldierIndex+=1
> 
> ```

i tough you where using **griffin-riders** therefore soldiers will just blow the minefield up

> [@QinWentian](#):
>
> ```python
> if enemy.type == 'fangrider' and hero.distanceTo(enemyyyy):
> return heroAttack()
> 
> ```

use `hero.distanceTo(enemyyyy) < (the distance you want)`

---

<div class="post-metadata">

**Author:** ![QinWentian](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/qinwentian/32/17063_2.png) [@QinWentian](https://discourse.codecombat.com/u/QinWentian)\
**Post date:** [January 7, 2021, 9:10am UTC](https://discourse.codecombat.com/t/reaping-fire-python-please-help/26374/12 "2021-01-07T09:10:29Z")

</div>

The soldiers is actually a variable for griffin riders, sorry for the confusion XD
