[Solved] Mad Maxer: Not Greedy Enough

while(coinIndex < coins.length){
        var coin = coins[coinIndex];
        var rating = coin.value / hero.distanceTo(coin);
        if(rating > maxRating){
            bestCoin = coin;
            maxRating = rating;
        }
        coinIndex++;
    }

This code works in practice, but cannot succeed when I press submit. I’m using move instead of moveXY like the hints suggest, but yet I always ending falling short in the submit run, yet in practice, I beat him 73 to 71. I even tried to get my pet to steal coins from the other side, but they’re too heavy for him, sadly. Any help?

change it to coinIndex += 1

Aren’t those the same thing?

(post deleted by author)

Alright, I changed from coinIndex++; to coinIndex += 1; and now I don’t even win in practice.

That’s python. coinIndex ++; is correct in Javascript. Please could you post your full code @DragonAce, I can’t see anything wrong with the section you’re showing.
Danny

Full Code:
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(coinIndex < coins.length){
        var coin = coins[coinIndex];
        var rating = coin.value / hero.distanceTo(coin);
        if(rating > maxRating){
            bestCoin = coin;
            maxRating = rating;
        }
        coinIndex++;
    }
    if(bestCoin){
        hero.move(coin.pos);
    }
}

Two mistakes here:

You can probably see that one.

And:

This isn’t a mistake, but couldn’t you add something that checked if the coin was on the left side of the map?
Danny

Thanks. I feel a bit silly now. As for the second thing, my hero seemed smart enough to not run into the wall after I unequipped the enchanted lenses. I’ve found that they’re usually more trouble than they’re worth, and the Fine Telephoto Glasses work just fine for basically everything. Nonetheless, thanks for the help!

2 Likes

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