# Reaping Fire Python Heeeellllllp

**URL:** <https://discourse.codecombat.com/t/reaping-fire-python-heeeellllllp/36827>\
**Category:** Level Help\
**Created:** [February 1, 2024, 7:13am UTC](https://discourse.codecombat.com/t/reaping-fire-python-heeeellllllp/36827 "2024-02-01T07:13:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vivian\_lizard](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vivian_lizard/32/36833_2.png) [@vivian\_lizard](https://discourse.codecombat.com/u/vivian_lizard)\
**Post date:** [February 1, 2024, 7:13am UTC](https://discourse.codecombat.com/t/reaping-fire-python-heeeellllllp/36827/1 "2024-02-01T07:13:15Z")

</div>

I really don’t get what is wrong with my code, please help! Thank you 🥰

```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"):
        hero.summon("griffin-rider")
        return "griffin-rider"
    # If there is a fangrider on your side of the mines, return "fight-back"
    fangrider = hero.findNearest(hero.findByType("fangrider", hero.findEnemies()))
    if fangrider and fangrider.pos.x < 37:
        return "fight-back"
    # Otherwise, return "collect-coins"
    else:
        return "collect-coins"

def commandAttack():
    # Command your griffin riders to attack ogres.
    for friend in hero.findFriends():
        if friend.type == "griffin-rider":
            enemy = friend.findNearestEnemy()
            if enemy and enemy.type != "fangrider":
                hero.command(friend, "attack", enemy)
    pass

def pickUpCoin():
    # Collect coins
    coin = hero.findNearestItem()
    hero.move(coin.pos)
    pass

def heroAttack():
    # Your hero should attack fang riders that cross the minefield.
    enemy = hero.findNearest(hero.findByType("fangrider"))
    if enemy.pos.x < 37:
        hero.attack(enemy)
    pass

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

```

---

<div class="post-metadata">

**Author:** ![vivian\_lizard](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vivian_lizard/32/36833_2.png) [@vivian\_lizard](https://discourse.codecombat.com/u/vivian_lizard)\
**Post date:** [February 1, 2024, 7:14am UTC](https://discourse.codecombat.com/t/reaping-fire-python-heeeellllllp/36827/2 "2024-02-01T07:14:38Z")

</div>

The griffin-riders will go to the fire-traps because the fangriders go there and then KABOOM!

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [February 1, 2024, 7:55am UTC](https://discourse.codecombat.com/t/reaping-fire-python-heeeellllllp/36827/3 "2024-02-01T07:55:54Z")

</div>

> [@vivian\_lizard](#):
>
> `if friend.type == "griffin-rider":`

try making this  
`if friend and friend.type == "griffin-rider"`

im not sure how effective these would be but doesnt harm to try

> [@vivian\_lizard](#):
>
> `hero.move(coin.pos)`

and for this try using  
`hero.moveXY(coin.pos.x, coin.pos.y)`

> [@vivian\_lizard](#):
>
> `if enemy.pos.x < 37:`

also here make it:  
` if enemy and enemy.pos.x < 37:`

---

<div class="post-metadata">

**Author:** ![Watamelon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/watamelon/32/43741_2.png) [@Watamelon](https://discourse.codecombat.com/u/Watamelon)\
**Post date:** [February 1, 2024, 3:24pm UTC](https://discourse.codecombat.com/t/reaping-fire-python-heeeellllllp/36827/4 "2024-02-01T15:24:48Z")

</div>

Your code is working fine for me, but here are a few suggestions

`fangrider = hero.findNearest(hero.findByType("fangrider", hero.findEnemies()))`

From the code I see, your “fight-back” method isn’t being called. The method findByType() takes **only** 1 argument, fangriders are always enemies, make sure to remove that so that the function would work.  
`fangrider = hero.findNearest(hero.findByType("fangrider"))`

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/e/3/e39014b90a3858769802e9add8364c51e868dba1.jpeg)

Also sometimes your code might face a seed problem, so you will have to resubmit multiple times.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a9445509d1a758c41b5ddcddc8c8e20a5dedb67f.png) [@system](https://discourse.codecombat.com/u/system)\
**Post date:** [February 2, 2024, 6:38am UTC](https://discourse.codecombat.com/t/reaping-fire-python-heeeellllllp/36827/5 "2024-02-02T06:38:33Z")

</div>

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
