# Hunting Party c++ \[CLOSED\]

**URL:** <https://discourse.codecombat.com/t/hunting-party-c-closed/34662>\
**Category:** Level Help\
**Created:** [January 3, 2023, 12:28pm UTC](https://discourse.codecombat.com/t/hunting-party-c-closed/34662 "2023-01-03T12:28:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [January 3, 2023, 12:28pm UTC](https://discourse.codecombat.com/t/hunting-party-c-closed/34662/1 "2023-01-03T12:28:58Z")

</div>

```python
int main() {
    // You can use findNearestEnemy() on your soldiers to get their nearest enemy instead of yours.
    while (true) {
        auto friends = hero.findFriends();
        auto weak_friend = null;
        auto low_friend = 99999;
        // Use for-loop and for each friend:
        for(int i = 0; i < friends.length; i ++){
            // If they see an enemy then command to attack.
            auto friend = friends[i];
            auto enemy = friend.findNearestEnemy();
            if(friend.health < low_friend){
                weak_friend = friend;
                low_friend = friend.health;
            }
            
            if(enemy){
                hero.command(friend, "attack", enemy);
            }else{
                hero.command(friend, "move", {friend.pos.x + 15, hero.pos.y});
            }
            
            if(weak_friend){
                hero.command(weak_friend, "move", {weak_friend.pos.x - 30, weak_friend.pos.y});
            }
            
            // Command to move east by small steps.
        }
        
        auto enemy = hero.findNearestEnemy();
        if(enemy){
            if(hero.isReady("jump") && hero.isReady("cleave")){
                hero.jumpTo(enemy.pos);
                hero.cleave(enemy);
            }else{
                hero.attack(enemy);
            }
        }else{
            hero.moveXY(hero.pos.x + 15, hero.pos.y);
        }
    }
    return 0;
}

```

soldier moving all together in one place  
how do i fix this?
