[SOLVED] Help! Resource Valleys

My code
def commandPeasant(peasant, coins):
    # Find the nearest coin to the `peasant` from the `coins` array,
    items = hero.findItems()
    peasants = hero.findByType("peasant")
    for peasant in peasants:
        item = peasant.findNearest(hero.findItems())
        hero.command(peasant, "move", {'x':item.pos.x , 'y':item.pos.y})
    # Command the peasant "move" to the nearest coin.
    
    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 error

image

My equipment

Link (non-sub)

https://codecombat.com/play/level/resource-valleys?

Lydia
2 Likes

Try fixing that and should be better, at least.

What do you mean?
Lydia

2 Likes

hm your is different to mine this is the first part of it idk if I can post it cause it said no solutions but this is just part of one so I’ll delete this if its not allowed

def commandPeasant(peasant, coins):
    # Command the peasant to find the nearest of their coins array:
    item = peasant.findNearest(coins)
    if item:
        hero.command(peasant, "move", item.pos)

edit: please tell me if this is not allowed

oh then i really have no idea sorry
edit: wait did you solve it?

Yes. Thanks for the help!
Lydia

2 Likes

your welcome(pretty sure that was my first time helping someone solve it)

2 Likes

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