# 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

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

1 Like

what do you mean? 200

1 Like

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

1 Like

No, itâ€™s Python (20 chars)

.

they do have } in javascript right?

1 Like

Itâ€™s just an array, if you didnâ€™t get it.

1 Like

i have never used that thoughâ€¦

1 Like

Yes, but sometimes you need it.

1 Like

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

1 Like

And he has `:` in ends of Whiles, defs.

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

1 Like

No, but my brother did.

1 Like

did he use the } thing?

1 Like

Yes, but everywhere.

1 Like

i have seen level helps that use } a lot and its javascriptâ€¦