I have function for looting coins. The main idea is to create a dictionary of coins for each peasant.
I’ve tested this function in pure Python and it’s working like a charm.
But here i have problem that this part coinsForPeasants[nearestPeasant].append[c] isn’t adding anything to the array.
Here is the code:
def peasantPickUpCoin():
coins = self.findItems()
peasants = self.findByType("peasant")
coinsForPeasants = {}
for f in peasants:
coinsForPeasants[f] = []
for c in coins:
nearestPeasant = c.findNearest(peasants)
coinsForPeasants[nearestPeasant].append[c]
self.say(coinsForPeasants[nearestPeasant])
for fr in peasants:
myCoins = coinsForPeasants[fr]
coin = fr.findNearest(myCoins)
if coin:
self.command(fr, "move", coin.pos)