Hi everyone, I’ve been stuck at this level for days and cannot figure out why. My hero is not going for the closest coin but always going for the second closest so I cannot get enough coins before time runs out.
Please check out my code below:
while True:
closestGold = None
minGoldDist = 9001
coinIndex = 0
coins = hero.findItems()
# Find the closest coin that is gold.
# Remember that gold coins have a value of 3.
while coinIndex < len(coins):
coin = coins[coinIndex]
if coin and coin.value == 3 and hero.distanceTo(coin) < minGoldDist:
closestGold = coin
minGoldDist == hero.distanceTo(closestGold)
coinIndex += 1
if closestGold:
#Now go to the closest gold coin and get it!
hero.moveXY(closestGold.pos.x, closestGold.pos.y)
pass