Hello there,
I’m stuck at Sarven Treasure, like the title tells you.
Here the Code:
function findOptimalCoin(coins){
var optimalCoin = null;
var coinIndex = 0;
var mostValueCoin = 0;
while (coinIndex < coins.length) {
var coin = coins[coinIndex];
var value = coin.value;
var distance = hero.distanceTo(coin);
if (value / distance > mostValueCoin) {
mostValueCoin = value / distance;
optimalCoin = coin;
}
coinIndex++;
}
return optimalCoin;
}
while(true){
var coins = hero.findItems();
var coin = null;
coin = findOptimalCoin(coins);
var enemies = hero.findEnemies();
var enemy = hero.findNearest(enemies);
if(enemy){
var ogerDistance = hero.distanceTo(enemy);
if(ogerDistance > 10){
hero.moveXY(coin.pos.x, coin.pos.y);
}
else if(ogerDistance <= 10){
if (hero.pos.x <= 40 && hero.pos.y <= 35 ){
hero.moveXY(5, 20);
}
else if (hero.pos.x <= 40 && hero.pos.y >= 35){
hero.moveXY(5, 50);
}
else if (hero.pos.x >= 40 && hero.pos.y <= 35){
hero.moveXY(76, 20);
}
else if (hero.pos.x >= 40 && hero.pos.y >= 35){
hero.moveXY(76, 51);
}
}
}
else if(coin){
hero.moveXY(coin.pos.x, coin.pos.y);
}
}
Im looking for the best Coin. When there is an Enemy more than 10 away take it.
If it’s closer than 10 move to the closest Teleport.
When there is no enemy grab the best Coin.
My Problem is, that when an Enemy is close to me, Hero runs into the correct Teleport. But then instead of grabbing more Coins he goes to the same Teleport all over again.
Thx in advance
P.S.: Sorry for the format but it’s not working like supposed.