Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Https://codecombat.com/play/level/mad-maxer-sells-out?


#1

what am I doing wrong?

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

#2

Put this in the while loop


#3

problem solved by half. I have a hero running on gold for height. first 2 then 3 then 5. not the nearest one runs. How to make it run on a close gem?


#4

You have to check the distance of the coin after checking that the value is 3.


#5

I still haven’t solved it. do not understand what and how should check you write.


#6

See the additional comments:

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