Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Mad-Maxer gets greedy

You’re missing a line here. You have to update maxRating’s value, otherwise it will always be 0 and all the coins will be classed as the bestCoin.

1 Like

Hi @Deadpool198,

Thank you for your answer, with some changes it works better, but i still loses a few coins

while coinIndex < len(coins):
        coin = coins[coinIndex]
        distance = hero.distanceTo(coin)
        value = coin.value
        if value/distance > maxRating:
            maxRating = value/distance
            bestCoin = coin
        coinIndex += 1