Help with infinity cycle

What doing else code work very-slow? Its problem on all level where command units.

Hm, it’s the second level where you have problems with slow code. Maybe it’s a problem with Lua interpreter. Just for curiosity, could you rewrite your algorithm in Python or JS (word by word translation with the same logic) and check?

Ok! I try and write.

Well, nothing changed=(
Maybe not enough computer power, although he is not so weak …

I am not familiar with lua, could you post your python/javascript code so i can look at that to see if there is a problem in it?

In this time it work slowly, but not have error for infinity cycle=)

def commandSoldier(soldier, soldierIndex, numSoldiers):
    angle = Math.PI * 2 * soldierIndex / numSoldiers
    defendPos = {"x": 41, "y": 40}
    defendPos.x += 10 * Math.cos(angle)
    defendPos.y += 10 * Math.sin(angle)
    hero.command(soldier, "defend", defendPos);
        hero.command(soldier, "move", {"x":43,"y":38})

# Найдите самую крепкую цель (больше всего здоровья)
# Эта функция что-то возвращает! Когда Вы вызываете функцию, то получаете от неё какое-то значение.
def findStrongestTarget():
    bestTarget = None
    enemies = hero.findEnemies()
    # Определите, у какого из врагов больше всего уровень здоровья и направьте метод bestTarget на этого врага.
    for i in range(len(enemies)):
        if enemies[i].health>25:
            return bestTarget 
            return None

# Если у врага, определенного как strongestTarget больше 15 единиц здоровья, атакуйте его. Иначе, атакуйте ближайшего врага.
def commandArcher(archer):
    nearest = archer.findNearestEnemy()
    if archerTarget:
        hero.command(archer, "attack", archerTarget)
    elif nearest:
        hero.command(archer, "attack", nearest)

archerTarget = None

while True:
    # Если враг, определенный как archerTarget мертв или не существует, найдите нового.
    if not archerTarget or <= 0:
        # Установите целью (или "аргументом") функции archerTarget, значение, возвращенное функцией findStrongestTarget().
        archerTarget = findStrongestTarget()

    friends = hero.findFriends()
    soldiers = hero.findByType("soldier")
    # Create a variable containing your archers.
    archers = hero.findByType("archer")
    for i in range(len(soldiers)):
        soldier = soldiers[i]
        commandSoldier(soldier, i, len(soldiers));

    # Используйте функцию commandArcher() для управления своими лучниками.
    for q in range(len(archers)):
        archer = archers[q]
        commandArcher(archer, q, len(archers));

You need to find the strongest one, instead you search an enemy with >25 health. As the result your archers are not effective as they can be.

        hero.command(soldier, "move", {"x":43,"y":38})

I think you can try lower values to retreat

I dont think so… i dont understand how work enother code, but me kill any time. With this code i win=)
Archers very effective, but code slowly…

What is the level? … (dots for length to allow post)