Hi,
I’m trying to complete the Diamond Dozen level.
I believe my code is working in that it is going for the item with the best value/distance ratio but I never pass the level, message says ‘Didn’t collect the optimal amount of coins’
if it’s a question of which weapon or other item to use then I’ve no idea which combination should be used (and that doesn’t seem fair as it’s a totally random choice)
If it is however my rubbish coding then can someone give me a clue please as I think the value optimisation part of the code is correct.
Many thanks,
Below is the code I am currently trying
Claim the coins while defeating the marauding ogres.
# Loop over the items array.
# Find the item with the highest valueOverDistance()
while itemsIndex<len(items):
if items[itemsIndex].value>bestValue:
bestItem=items[itemsIndex]
bestValue=bestItem.value
itemsIndex += 1
return bestItem
def bestAtt(enemy):
while enemy.health>0: #if hero.isReady(“jump”): #hero.jumpTo(enemy)
if hero.canCast(“chain-lightning”, enemy):
hero.cast(“chain-lightning”, enemy)
elif hero.isReady(“cleave”) and hero.distanceTo(enemy)<5:
hero.cleave(enemy)
else:
hero.attack(enemy)
while True:
enemies = hero.findEnemies()
enemy = findMostHealth(enemies)
if enemy and enemy.health > 15:
while enemy.health > 0:
bestAtt(enemy)
else:
coins = hero.findItems()
coin = None
coin = findBestItem(coins)
if coin:
if hero.isReady(“jump”):
hero.jumpTo(coin)
else:
hero.moveXY(coin.pos.x, coin.pos.y)
Hello, everything is right except for the findBestCoin() function, you should define item in that function like you defined enemy in the first one, also the
if items[itemsIndex].value > bestValue:
bestItem = items[itemsIndex]
bestValue = bestItem.value
the .value part of that is wrong, it’s using distance as well, not just value, but you made a function for that earlier and you just put your item variable in the brackets of the function that you made. (it’s the one your not using)
hope this helps
I emulated the function findBestItem(items) and it seems right to me.
Edit: @Deadpool198 yes, the function "valueOverDistance() " is never used.
So, if you want to follow the predefined logic in the while loop you put findBestItem(items) function: