Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Fail the two flowers[SOLVED]


#1

I don’t understand why I fail the mission

# Si le paysan est blessé, les fleurs rétréciront.

def summonSoldiers():
    if hero.gold >= hero.costOf("soldier"):
        hero.summon("soldier")

# Define the function: commandSoldiers
def commandSoldiers():
    friends = hero.findFriends()
    soldiers = hero.findByType("soldier")
    for soldier in soldiers:
        hero.command(soldier, "defend", peasant.pos)
# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
    item = hero.findNearestItem()
    if item:
        hero.move({"x":item.pos.x,"y":item.pos.y})
peasant = hero.findByType("peasant")[0]


while True:
    summonSoldiers()
    commandSoldiers()
    pickUpNearestCoin()

#2

what happens? do you get an error message?


#3

No my troops die and the enemy kill the peasant


#4

I just ran your code and it’s working but you don’t produce enough troops to support an effective defense. If you can, try using Pender. Pender is the fastest and can gather coins the quickest, especially if you can cast haste and reset the cooldown on haste along with using mana-blast. That way your hero is participating in the killing of enemies without interrupting the gathering of coins.


#5

yeah but he is for sub only so what can I do ?


#6

As you can see in the below pic, others have successfully passed the level using similar code to yours using Ida, Anya, Alejandro, and Tharin as heroes. What gear are you using? Are you using fast boots? The faster you go, the more coins you can collect and the more soldiers you can summon. Also, try submitting it anyway, even though it isn’t passing with the current seed and see if you can get another seed that passes.

TwoFlowers


#7

Boots
and I changed my script

# Si le paysan est blessé, les fleurs rétréciront.

def summonSoldiers():
    if hero.gold >= hero.costOf("soldier"):
        hero.summon("soldier")

# Define the function: commandSoldiers
def commandSoldiers():
    friends = hero.findFriends()
    soldiers = hero.findByType("soldier")
    for soldier in soldiers:
        hero.command(soldier, "defend", peasant.pos)
# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
    item = hero.findNearestItem()
    if item:
        hero.move({"x":item.pos.x,"y":item.pos.y})
peasant = hero.findByType("peasant")[0]

def valueOverDistance(item):
    return item.value / hero.distanceTo(item)

def findBestItem(items):
    bestItem = None
    bestValue = 0
    itemsIndex = 0
    
    # Loop over the items array.
    # Find the item with the highest valueOverDistance()
    while itemsIndex < len(items):
        item = items[itemsIndex]
        if item.value/ hero.distanceTo(item) > bestValue:
            bestItem = item
            bestValue = valueOverDistance(item)
        itemsIndex += 1
    return bestItem


while True:
    summonSoldiers()
    commandSoldiers()
    items = hero.findItems()
    
    if items:
        
        coins = hero.findItems()
        coin = None
        coin = findBestItem(coins)
        if coin:
            hero.moveXY(coin.pos.x,coin.pos.y)

        ```

#8

I run your first code and changed only the defend target: not the peasant but the place between the two flowers. No one died…


#9

OMG THANKS !!! (20 characters)