[SOLVED]Гора Клаудрип.Чужой меч (Mount Cloudrip. Borrowed Sword)

Что здесь не так? Лучники обстреливают слабых, в итоге остаются йети и они добивают лучников.

// На этом уровне герою не нужно сражаться.
// Прикажи своим лучникам стрелять во врагов с наибольшим уровнем здоровья!

var friend = hero.findNearest(hero.findFriends());
var enemies = hero.findEnemies();
var maxhealth = 0;
var strongestenemy = null;

while(true) {
for (var i = 0; i < enemies.length; i++) {
var enemy = enemies[i];
if (enemy.health > maxhealth) {
maxhealth = enemy.health;    
strongestenemy = enemy;
}
if (strongestenemy) {
hero.command(friend, "attack",  strongestenemy);
}
} 
}

Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!
what level is this @Zhekaman

edit: incorrect translation by google translate

Здесь огры сражаются с йети. Моя задача - приказывать лучникам обстреливать самого сильного из врагов. Кто-нибудь из лучников должен выжить

как называется уровень?

The level’s name is Borrowed Sword

Вы находите ближайшего друга. Это будет командовать только ближайшим другом, вы должны командовать всеми своими друзьями.

You are finding the nearest friend. This will only command the nearest friend, you should command all your friends.

 while True:   
    friends = hero.findFriends()
    for friend in friends:
        if friend:
            #command your friends

This is python

It does not help. Archers do not have time to kill enemies

Can you show what happened with a screen shot

1 Like

What is your current code

var health = 0;
var strongestenemy = null;
while (true) {
var enemies = hero.findEnemies();
var friends = hero.findFriends();
for (var i = 0; i < enemies.length; i++) {
    var friend = friends[i];
    var enemy = enemies[i];
    if (enemy.health > health) {
        health = enemy.health;
        strongestenemy = enemy;
    }
   
} 
if (friend) {
        hero.command(friend, "attack", strongestenemy);
    }
}

you might want to put these in the loop

2 Likes

It worked. Thank you so much! :slightly_smiling_face:

1 Like

Your welcome glad to help

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.