Hello guys!,
This is my first post in the platform, sorry if it is not the correct place for my question.
Here you can see my code about how to obtain 60 coins before the decision to move and build the fence.
The problem here is the “counter”, for some reason it doesn’t match with the real one that you can see up and right in the corner. The hero (function) is not considering the real value of each different coin. I can confirm it using the function hero.say(coinCount) after each coin taken.
I have made a lot of changes and I dont know how to fix it and with this problem the hero will never “understand” he has already have 60 coins.
coinCount = 0
while True:
closestCoin = None
minDistance = float('inf')
coins = hero.findItems()
for coin in coins:
distance = hero.distanceTo(coin) / coin.value
if distance < minDistance:
closestCoin = coin
minDistance = distance
if closestCoin:
hero.moveXY(closestCoin.pos.x, closestCoin.pos.y)
coinCount += closestCoin.value
hero.say(coinCount)
if coinCount >= 60:
break