Mad Maxer.... Again (Gets Greedy (Help))

In this level my hero does nothing, so I’m asking for help.(I didn’t know how to explain what my hero does but yeah).

here’s my code:

// Collect more coins than your doppelganger.
// You only have a few seconds to collect coins. Choose your path wisely!
while(true) {
    var bestCoin = null;
    var maxRating = 0;
    var coinIndex = 0;
    var coins = hero.findItems();
    // Try calculating "value / distance" to decide which coins to get.
    while (coins.value < 4) {
        hero.moveXY(coin.pos.x,coin.pos.y);
    }
    
}

That does not suppose to be in your code. First loop over each coin. After that try to put in a variabile called rating the coin.value/hero.distanceTo(coin) and then check if rating is bigger than maxRating and if that is the case, update the maxRating to rating and update bestCoin to coin. After you looped over all coins, then check if bestCoin exists and if so, moveXY to its position.

Andrei

What??I’m confused???

What do you not understand?

Andrei

@Monsty, i have a good value over distance recipe:

bestCoin = None
gold = 3
silver = 2
bronze = 1
coinValue = gold or silver or bronze
minGoldDist = coinValue * 10

@Monsty do you still need help at this level or I mark this topic as solved?

I still need help but you may help on all the others too but I’ll respond tomorrow.

The extra levels I did while I waited for someone to reply are 4 so I thought the 4 levels would be enough before tomorrow and then I have less work so I don’t need to do anything this Saturday. (I said this so you won’t ask “Then what’s the point of making them today”)

Ok then! See you tomorrow!

Andrei

Hey I can help you. Why haven’t you looped through the array?

I dunno how to???

You should probably go back and learn from previous levels. I’ll help you any way.

while (cookieIndex < cookies.length) {

Okay @FalconX11_312 .

Remember,

practice = progress

:smile:

and

progress = greatness

:grin: :grin:

Did you solve it? Remember to loop through the array.

No not yet. My dad told me to do Khan Academy then I have to do my homework.