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

Алмазная дюжина


#1

Скажите пожалуйста, что не так с кодом?

Собирай монеты, разгоняя мародёрствующих огров.

def findMostHealth(enemies):
    target = None
    targetHealth = 0
    enemyIndex = 0
    while enemy

Index < len(enemies):
        enemy = enemies[enemyIndex]
        if enemy.health > targetHealth:
            target = enemy
            targetHealth = enemy.health
        enemyIndex += 1
    return target

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

# Возврати предмет с наибольшим значением `valueOverDistance(item)`.
def findBestItem(items):
    bestItem = None
    bestValue = 0
    itemsIndex = 0
    # Перебери массив предметов.
    # Найди предмет с наибольшим значением `valueOverDistance()`.
    if itemsIndex < len(items):
        item = items[itemsIndex]
        if valueOverDistance(items) > bestValue:
            bestValue = valueOverDistance(items)
            bestItem = item
        itemsIndex += 1
    return bestItem

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 = None
        coin = findBestItem(coins)
        if coin:
            hero.moveXY(coin.pos.x, coin.pos.y)

#3

Please learn to post your code correctly. The way it is now, we can’t see the structure. Help us help you. It’s very easy to do and just takes a tiny bit of effort. Please read this topic and format your code again correctly


#4

Thank you. I changed this post.