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

[SOLVED] Diamond Dozen Help!

 # Claim the coins while defeating the marauding ogres.

def findMostHealth(enemies):
    target = None
    targetHealth = 0
    enemyIndex = 0
    while enemyIndex < len(enemies):
        enemy = enemies[enemyIndex]
        if > targetHealth:
            target = enemy
            targetHealth =
        enemyIndex += 1
    return target

def valueOverDistance(item):
    return item.value / hero.distanceTo(item)

# Return the item with the highest valueOverDistance(item)
def findBestItem(items):
    bestItem = None
    bestValue = 0
    itemsIndex = 0
    # Loop over the items array.
    # Find the item with the highest valueOverDistance()
    while itemsIndex < len(items):
        item = items[itemsIndex]
        if item.value/hero.distanceTo(item) < bestValue:
            bestItem = item
            bestValue = valueOverDistance(item)
        itemsIndex += 1
    return bestItem

while True:
    enemies = hero.findEnemies()
    enemy = findMostHealth(enemies)
    if enemy and > 15:
        while > 0:
        coins = hero.findItems()
        coin = None
        coin = findBestItem(coins)
        if coin:

After attacking , my hero just waits for the next wave. Whats wrong?

You should put


Instead of this

I tried that, but it didn’t work either. “hero.move” was something I found in another topic about this level.


In the place of this, you should use something like

valueOverDistance(item) > 

Thank you! It worked fine.

No problem! Glad I could help :slight_smile: