Help! mad maxer gets greedy


#1

At 20 seconds the hero rests against the wall.
Level https://codecombat.com/play/level/mad-maxer-gets-greedy?
Снимок

while True:
    bestCoin = None
    maxRating = 0
    coinIndex = 0
    coins = self.findItems()
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        coinIndex += 1
        if coin.value / self.distanceTo(coin) > maxRating:
            maxRating = coin.value / self.distanceTo(coin)
            bestCoin = coin
        
    if bestCoin:
        self.moveXY(bestCoin.pos.x, bestCoin.pos.y)


#2

the only thing I did differently than your code was to define value and distance and use them in the first if statement. I don’t believe that makes any difference though. I believe the issue is that you incremented before the value / distance computation. I always increment last, after the computations.

distance = hero.distanceTo(coin)
value = coin.value

Also, when running the code before submitting, it would never collect enough to beat the doppelganger. But when submitted, it wins every time.


#3

If I increment after computing, my code does not even start. Do not zayu why. All options pereprobyval, the hero rests against the wall at 20 seconds. Give your source, please.


#4

I just ran your code exactly as you have it written and it worked fine. Now, I think you have a gear problem. What glasses are you using? I’m using fine wooden glasses with range of 10 meters. If you’re using long range glasses it would explain why your character is trying to get to the other side and thus the “I can’t get there” message. Try using shorter range glasses.


#5

Thank you.) I used the “Sees through walls” glasses. The code works. but for some reason, at the end of the double collects one coin more. (Shoes “Leather Boots”)


#6

The problem is solved. Everything works, thank you!