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

Mad Maxer Gets Greedy - have problem

while (true) {
    var bestCoin = null;
    var maxRating = 0;
    var coinIndex = 0;
    var coins = hero.findItems();
    while (coinIndex < coins.length) {
        var coin = coins[coinIndex];
        var distance = hero.distanceTo(coin);
        var value = coin.value;
        coinIndex += 1;
        if (value / distance > maxRating) {
            maxRating = value / distance;
            bestCoin = coin;
    if (bestCoin) {
        hero.moveXY(bestCoin.pos.x, bestCoin.pos.y);

I have a problem with my code. My hero collect the same quantity coins that doublehero. I don’t know what to do. Help me!

Hi @Nikita_Knaub welcome to the CodeCombat discourse.
You need to add a check to see whether the coins pos.x is less than 39 (the halfway line) otherwise you’ll try and get coins from the other side.
Also try and use move, it works without it, but it’s a lot better with move.
If you don’t have any move boots you can buy the fine boots quite cheaply and just use: hero.move(bestCoin.pos).
I hope this helps,