[Solved] Mad Maxer Gets Greedy

while True:
    bestCoin = None
    maxRating = 0
    coinIndex = 0
    coins = hero.findItems()
    # Try calculating "value / distance" to decide which coins to get.
    for coin in coins:
        if coinIndex < len(coins):
            value = coin.value
            distance = hero.distanceTo(coin)
            if value / distance > maxRating:
                bestCoin = coin
                maxRating = value / distance
                coinIndex += 1 
                if bestCoin:
                    hero.move(bestCoin.pos)```

This is my code - can anyone help point me towards what I am doing wrong?  Thanks

You have to update coinIndex after you move to the best coin.Also you should use moveXY because it is the one that’s required to use in this level. move() is from the mountain levels. And this level uses moveXY @mratranslate

while True:
    bestCoin = None
    maxRating = 0
    coinIndex = 0
    coins = hero.findItems()
    # Try calculating "value / distance" to decide which coins to get.
    for coin in coins:
        if coinIndex < len(coins):
            value = coin.value
            distance = hero.distanceTo(coin)
            if value / distance > maxRating:
                bestCoin = coin
                maxRating = value / distance
                if bestCoin:
                    hero.moveXY(bestCoin.pos.x, bestCoin.pos.y)
                    coinIndex += 1 

I changed my code to add to index as you said but it doesn’t work still. Anya collects far too slow to beat the CPU and also at times it says “I can’t get there”. Also I used moveXY as you said but the actual hints say to use ‘move’. Either way it doesn’t work :frowning:

I got some help and it seems the final if statement should match-up to for coin in coins. Also I used ‘move’. Then it worked.