Mad Maxer Gets Greedy. So close, but so far


I have been banging my head against a wall on “Mad Maxer Gets Greedy” for an embarrassing amount of time.

I can match the doppleganger exactly with a simple nearest coin fetch. But every permutation of biasing towards value over distance I’ve come up with gets me lower performance.

I’ve tried:

– Simple value / distance (with various coefficients.)
– Skipping pennies (unless there’s nothing else, as skipping them altogether will block respawns)
– Simple distance for coin values > 1 (then pennies when there’s nothing else)
– Simple distance for coin values > 2.(then the rest when there’s nothing else)

I’m stumped and stuck.

Thoughts? Am I missing something obvious here? At this point I’m just sick of looking at it.

Thanks o7


There is nothing wrong with any of those code permutations…

The problem is that you aren’t watching what your hero does…

Run the code, and watch your hero…

THEN read this

Your hero kicks butt just fine until it tries to grab coins on the other side of the divider…
All you need is some sort of “skip coins with x>#”


If that were true I’d expect him to get stuck against the right wall. All the pathing is internal to the left side of the play field. I really don’t think any of the right-side coins are entering the items array.


What glasses are you using?

The level doesn’t care if you collect all the coins or not, it removes and adds new coins by time.

All I need to do to your code is add a ignore coins on other side of wall and I win.


It’s an old pair. I can’t see through stuff.


I can’t see through stuff either . . . 1) only one pair can do that and I don’t have it, 2) the columns don’t block sight…

Therefor, I’d say that you didn’t do as I suggested, and go watch your hero…


In fact I did exactly as you suggested (hero didn’t move unambiguously toward items on the other side of the columns) and I added a filter for items with pos.x < the left side of the columns and it didn’t appreciably change performance.


Then something else must be going on.

I copied and pasted your code the only change I made was to add the filter to ignore x > the column.

Hero, Anya, no speed ring and I win just fine.

Try submitting, maybe you have a really bad seed.


I’ve written and rewritten this one so many times and swear I’ve done this in past iterations, but in my most recent try after updating maxRating with … maxRating = coin.value / self.distanceTo(coin) … which is the calculation as making the determination that the target is better than current bestCoin, right before setting bestCoin = coin, it worked.

Keep it simple. And my guy never tried to go to the right side either. I am using the +2m/s boots but since the doppleganger can finish while my guy gets another set of coins (happened many times while i was losing) i suspect that it adjusts the respawns based on your guy’s speed.


My code was this:

coin = self.findNearestItem()
if coin:
coinPos= coin.pos
coinX = coin.pos.x
coinY = coin.pos.y
self.moveXY(coinX, coinY)

but I just collected the same amount of coins as the doppel ganger.


Please format your code as specified in the FAQ. All you have to do is highlight your code, then click the </> button.


this is what I tried:

bestCoin = None
maxRating = 0
coinIndex = 0
coins = self.findItems()
# Try calculating “value / distance” to decide which coins to get.

    # Find the closest coin that is gold.
while coinIndex < len(coins):
    coin = coins[coinIndex]
    distance = self.distanceTo(coin)
    value = coin.value
    # Remember that gold coins have a value of 3.
    if value/distance > maxRating:
        if value > 1:
            bestCoin = coin
            maxRating = value/distance
    coinIndex += 1

it took a few tries but after that I collected more coins than my dubbeldanger.


The usual rating method of value/distance or value/(distance^2) should be enough to beat the AI. What you need to take into consideration is that you can see the coins on the other side of the field, and may go towards them, but obviously never get them. So simply filter out coins that are out of your reach.

You could also try to move towards the center when there are no coins, so you could get to them quicker when they appear.

Also, I hope you use move() and not moveXY()



Wow, I was banging my head against the wall on this level too wondering why I kept matching the doppleganger exactly. Then I submitted instead of just running and I was successful. Must have been a bad seed initially. Woot! Thanks @Vlevo


@ant Wow… I was stuck until I switched moveXY to move, but I don’t understand why this makes a difference. Can you (or anyone else) explain?


I’m pretty sure move lets the hero calculate information while the hero is moving while moveXy makes you get to the location before you can calculate (I believe)


I believe that that is true because in Crag Tag (Cloudrip Mountain), the hero moves to a fixed coordinate using moveXY and cannot catch up to Pender, whereas using move, the hero constantly recalculates Pender’s position and is therefore able to catch up.