[SOLVED] Mad Maxer gets greedy -- Works but feels wrong

Hi everyone, I tried this code with the “+2m/s boots” but still couldn’t get enough coins

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

So I “patched” the if command line into if rating > maxRating and coin.pos.x < 38 and hero.distanceTo(coin) < 20: and it worked.
But I feel like this kinda is “cheating”. Is there another way to fix my original code?

Hi @Ephemera,
I think the problem is inside this if:

You also need to set maxRating to rating so that it’s comparing the coins to the value / distance of bestCoin instead of 0.

That’s it! Can’t believe I missed that! thank you so much @MarmiteOnToast

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.