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!