Well… I was playing with Phyton but I can’t beat this level.
I don’t know what’s wrong, so I hope you can help me <3
Here’s my code:
def commandPeasant(peasant, coins):
# Command the peasant to the nearest of their array
distance = 0
for i in coins:
coin = coins[i]
if distance == 0:
distance = peasant.distanceTo(coin)
item = coin
elif distance < peasant.distanceTo(coin):
distance = peasant.distanceTo(coin)
item = coin
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(friends[0], goldCoins)
commandPeasant(friends[1], silverCoins)
commandPeasant(friends[2], bronzeCoins)
if item.value == 3:
goldCoins.append(item)
if item.value == 2:
silverCoins.append(item)
if item.value == 1:
The above construction may work by pure luck, but generally is wrong. Do it the right way
in your code read carefully the hint:
// Command the peasant to the nearest of their array
function commandPeasant(peasant, coins) {
// You must get here a single coin from coins and tell the peasant to move there
// coins.pos is an array of points , not a single coin.pos
hero.command(peasant, “move”, coins.pos); // wrong
}
So how would I command the peasant to the nearest of their array? Do I do something like this?
function commandPeasant(peasant, coins) {
// Command the peasant to the nearest of their array
var coin = coins[0];
hero.command(peasant, “move”, coin.pos);
}
peasant has no peasant.findItems method. / and if he has it will be peasant.findItems()/
Your function is commandPeasant(peasant, coins), where you have the array coins as parameter.
So it will be:
function commandPeasant(peasant, coins) {
var coin = peasant.findNearest(coins);
hero.command(peasant, “move”, coin.pos);
}