Resource Valleys [level help]

# Collect all the coins!

def commandPeasant(peasant, coins):
    # Find the nearest coin to the `peasant` from the `coins` array,
    friends = hero.findFriends()
    for peasant in friends:
        coin= peasant.findNearestItem()
        
        if coin:
            hero.command(peasant, "move", {'x': coin.pos.x, 'y': coin.pos.y})
    pass

friends = hero.findFriends()
peasants = {
    "Aurum": friends[0],
    "Argentum": friends[1],
    "Cuprum": friends[2]
}

while True:
    items = hero.findItems()
    goldCoins = []
    silverCoins = []
    bronzeCoins = []
    for item in items:
        if item.value == 3:
            goldCoins.append(item)
        # Put bronze and silver coins in their approriate array:
        if item.value == 2:
            silverCoins.append(item)
        if item.value == 1:
            bronzeCoins.append(item)
    
    commandPeasant(peasants.Aurum, goldCoins)
    commandPeasant(peasants.Argentum, silverCoins)
    commandPeasant(peasants.Cuprum, bronzeCoins)

my code just makes one peasant move to the coin then it stops and says this
image

In the function, the peasant should go to the nearest coin from the coins array, not the nearest coin.

what do you mean? 200

You don’t ever use coins. The peasant has to go to the nearest coin in the coins array.

my new code still doesn’t work

# Collect all the coins!

def commandPeasant(peasant, coins):
    # Find the nearest coin to the `peasant` from the `coins` array,
    for peasant in friends:
        coins = peasant.findItems()
        coinIndex = 0
        while coinIndex < len(coins):
            coin = coins[coinIndex]
            hero.command(peasant, "move", coin.pos)
            coinIndex += 1
    pass
friends = hero.findFriends()
peasants = {
    "Aurum": friends[0],
    "Argentum": friends[1],
    "Cuprum": friends[2]
}

while True:
    items = hero.findItems()
    goldCoins = []
    silverCoins = []
    bronzeCoins = []
    for item in items:
        if item.value == 3:
            goldCoins.append(item)
        # Put bronze and silver coins in their approriate array:
        if item.value == 2:
            silverCoins.append(item)
        if item.value == 1:
            bronzeCoins.append(item)
    
    commandPeasant(peasants.Aurum, goldCoins)
    commandPeasant(peasants.Argentum, silverCoins)
    commandPeasant(peasants.Cuprum, bronzeCoins)

Try to write:

 for peasant in peasants:
        if peasant:
           coins = peasant.findItems()
           If coins:
              for coin in coins:
                  if coin:
                     hero.command(peasant, "move", coin.pos)
       
    pass

Also try to write

friends = hero.findFriends()

in While True.

i think he uses javascript instead of python

yes by the looks of it @Destroyer5023 is right @PeterPalov altough it might work adding what you need to add to complete the level @Jake_Doggy

No, it’s Python (20 chars)

.

they do have } in javascript right?

It’s just an array, if you didn’t get it.

i have never used that though…

Yes, but sometimes you need it.

im in mountains and ive never seen or used it and im almost done with mountains

And he has : in ends of Whiles, defs.

ok dont you need that anyway? (have you done javascript?)

No, but my brother did.

did he use the } thing?

Yes, but everywhere.

i have seen level helps that use } a lot and its javascript…