while True:
closestGold = None
minGoldDist = 9001
coinIndex = 0
coins = hero.findItems()
coin=coins[coinIndex]
# Найди ближайшую золотую монету.
# Запомни: золотая монета имеет ценность 3.
while len(coins)>coinIndex:
distance = hero.distanceTo(coin)
if coin.value==3 and distance<minGoldDist:
closestGold=coin
if closestGold:
#А теперь доберись до ближайшей золотой монеты и возьми её!
hero.moveXY(closestGold.pos.x, closestGold.pos.y)
coinIndex+=1
pass
while True:
# your code
coin=coins[coinIndex] # you don't need this line
# in your case coin = coins[0]
# Найди ближайшую золотую монету.
# Запомни: золотая монета имеет ценность 3.
while len(coins) > coinIndex:
# put coin = coins[coinIndex] # your coin variable will be undefined
# if you don't put this line
distance = hero.distanceTo(coin)
if coin.value==3 and distance < minGoldDist:
closestGold=coin
# minGoldDist = distance # change the min to gold distance
# with the current distance
# block of code that have to be
# outside the while len(coins) > coinIndex loop
coinIndex +=1
if closestGold:
#А теперь доберись до ближайшей золотой монеты и возьми её!
hero.moveXY(closestGold.pos.x, closestGold.pos.y)
pass