# Claim the coins while defeating the marauding ogres.
# If you defeat the ogre with the most health, the rest of the ogres will run!
# Coins vanish quickly after appearing, so be sure to find the best value!
def findMostHealth(enemies):
target = None
targetHealth = 0
enemyIndex = 0
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
if enemy.health > targetHealth:
target = enemy
targetHealth = enemy.health
enemyIndex += 1
return target
# Make a function named findOptimalCoin which returns the coin with the best value.
def findOptimalCoin(coins):
optimal = -1000
thione = None
for coin in coins:
if coin.value / self.distanceTo(coin) > optimal:
optimal = coin.value / self.distanceTo(coin)
thione = coin
return thione
# Coins rapidly appear and disappear, so pick the best coin.
# Optimize your path by going for the coin with the largest value over distance.
while True:
enemies = hero.findEnemies()
enemy = findMostHealth(enemies)
if enemy and enemy.health > 15:
while enemy.health > 0:
hero.attack(enemy)
else:
coins = hero.findItems()
coin = findOptimalCoin(coins)
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
What is wrong with my code?
To Be Honest Their Is Nothing Wrong With Your Code I Read It And Then Used It On The Same Level And It Said Success.
Then it could be an equipment issue?
What equipment should I use?
Post a screenshot of what you are wearing, that way we can tell
Okay I will do that now.
This is it.
you know, this should work. I tried this level with the same equipment and it worked.
Try Using Boots Of Leaping And If That Doesn’t Work Try Contacting @Nick.
Gotcha. @Wealthy-Boss
Nick won’t respond.
@Wealthy-Boss What equipment are you using.
Nevermind it was a bug. When i clicked submit it worked.
results are slightly different when I run vs when I submit. Submit gets more coins but apparently something is still wrong. Can anyone assist?
// Claim the coins while defeating the marauding ogres.
function findMostHealth(enemies) {
var target = null;
var targetHealth = 0;
var enemyIndex = 0;
while(enemyIndex < enemies.length) {
var enemy = enemies[enemyIndex];
if(enemy.health > targetHealth) {
target = enemy;
targetHealth = enemy.health;
}
enemyIndex += 1;
}
return target;
}
function valueOverDistance(item) {
return item.value / hero.distanceTo(item);
}
// Return the item with the highest valueOverDistance(item)
function findBestItem(items) {
var bestItem = null;
var bestValue = 0;
var itemsIndex = 0;
// Loop over the items array.
// Find the item with the highest valueOverDistance()
while(itemsIndex < items.length) {
var item = items[itemsIndex];
if (valueOverDistance(item) > bestValue) {
bestValue = item.value;
bestItem = item;
} itemsIndex ++ ;
}
return bestItem;
}
while(true) {
var enemies = hero.findEnemies();
var enemy = findMostHealth(enemies);
if(enemy && enemy.health > 15) {
while(enemy.health > 0) {
hero.attack(enemy);
}
} else {
var coins = hero.findItems();
var coin = null;
coin = findBestItem(coins);
if(coin) {
hero.moveXY(coin.pos.x, coin.pos.y);
}
}
}
Ah, yes. To clarify, run uses the same seed every run, making it easier to complete it with a specific code that only works for that certain seed. Submit on the other hand, uses a random seed every run, making it impossible to “hard-code” it and succeed. Since I’m horrible at JS, you might want to ask someone like @brooksy125.
I noticed that you are comparing the function valueOverDistance(item)
to bestValue, but then assigning the item.value to bestValue. Since the item value will be higher than item.value/ hero.distanceTo(item)
, your first item will always be returned as the best item.
if (valueOverDistance(item) > bestValue) {
bestValue = item.value; //change this value
Thanks. Didn’t occur to me that I could use the function again as an object itself. Code reuse I guess.