# Level mountain mercenaries

**URL:** <https://discourse.codecombat.com/t/level-mountain-mercenaries/3149>\
**Category:** Adventurer\
**Created:** [March 18, 2015, 9:53pm UTC](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149 "2015-03-18T21:53:47Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vettax](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vettax/32/1514_2.png) [@Vettax](https://discourse.codecombat.com/u/Vettax)\
**Post date:** [March 18, 2015, 9:53pm UTC](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149/1 "2015-03-18T21:53:47Z")

</div>

Hi,

I’ve got the feeling that I make all what was expecting for this level.  
I take the coins, build soldiers and command them to attack the enemies.  
But I do not produce enough soldiers, they’re all killed, and enemies attack me, and I’m dying.  
I’ve got the speed ring, so I’m not really lazzy to grab the gems, but it seems it’s not enough by far.  
Is there a balance problem, or is it a new very hard level ? This level looks more a simple way to learn command.

---

<div class="post-metadata">

**Author:** ![Vlevo](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vlevo/32/2074_2.png) [@Vlevo](https://discourse.codecombat.com/u/Vlevo)\
**Post date:** [March 19, 2015, 2:25am UTC](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149/2 "2015-03-19T02:25:46Z")

</div>

Let me guess . . . you are using moveXY

---

<div class="post-metadata">

**Author:** ![Vettax](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vettax/32/1514_2.png) [@Vettax](https://discourse.codecombat.com/u/Vettax)\
**Post date:** [March 19, 2015, 8:45am UTC](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149/3 "2015-03-19T08:45:41Z")

</div>

Yes. Why ? In this level, as coins are not moving and we don’t care about the enemy, move seems not required.  
Is there a known issue ?

---

<div class="post-metadata">

**Author:** ![tbm\_1981](https://avatars.discourse-cdn.com/v4/letter/t/45deac/32.png) [@tbm\_1981](https://discourse.codecombat.com/u/tbm_1981)\
**Post date:** [March 19, 2015, 10:59am UTC](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149/4 "2015-03-19T10:59:35Z")

</div>

Hello Vettax,

I experienced a similar issue. It seems that the number, timing, and strength of the incoming ogre scouts is too high relative to the soldiers I can produce. I haven’t been able to complete the level in the intended way, by utilizing the coins to build soldiers, yet. Instead, I found it easy to complete the level with a simple attack loop. FindNearest Enemy, Attack, Repeat.

I still want to complete the level by only summoning and commanding troops, but I haven’t been able to figure out how.

---

<div class="post-metadata">

**Author:** ![tbm\_1981](https://avatars.discourse-cdn.com/v4/letter/t/45deac/32.png) [@tbm\_1981](https://discourse.codecombat.com/u/tbm_1981)\
**Post date:** [March 19, 2015, 11:05am UTC](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149/5 "2015-03-19T11:05:26Z")

</div>

Vlevo,

Does the hero character’s moveXY method affect the commands given to the summoned soldiers? I infer from your question that might be true. Otherwise I see no problem in using moveXY. Could you explain a little more? What am I missing?

---

<div class="post-metadata">

**Author:** ![J\_F\_B\_M](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_f_b_m/32/2756_2.png) [@J\_F\_B\_M](https://discourse.codecombat.com/u/J_F_B_M)\
**Post date:** [March 19, 2015, 3:41pm UTC](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149/6 "2015-03-19T15:41:29Z")

</div>

While I cannot of course look into Vlevo’s intentions, I can assume a bit.

With `moveXY` you can only ever act after you finished moving and before starting your next move. If you decide to run 20 meters to the next coin, you’re almost 2 seconds (Anya/Tharin with default equipment) not in control of the situation. A Gem could spawn right next to you, and you would have no idea. You also collect a coin way before reaching it’s position (5 m before actually), so you don’t have to move the full way. Regardless, `moveXY` will continue until you reached the coins position.

You can also not issue new commands while you move (no control).

That is why I prefer `move` over `moveXY` in collection tasks.

---

<div class="post-metadata">

**Author:** ![Vlevo](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vlevo/32/2074_2.png) [@Vlevo](https://discourse.codecombat.com/u/Vlevo)\
**Post date:** [March 19, 2015, 5:23pm UTC](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149/7 "2015-03-19T17:23:59Z")

</div>

J\_F\_B\_M is correct about the reasons.

Now for “intentions” – I too couldn’t finish the level . . . until I made a simple switch: moveXY to move (my first failing code moveXY:weighted them, so I tried moveXY:nearest, again fail, so I tried move:nearest, yeah.)

So, my intention was to nudge you toward the dreaded “move”. (Hopefully, you can see where I stand on the issue, from the path of my attempts.) 😉

---

<div class="post-metadata">

**Author:** ![ninja\_star](https://avatars.discourse-cdn.com/v4/letter/n/b9e5f3/32.png) [@ninja\_star](https://discourse.codecombat.com/u/ninja_star)\
**Post date:** [March 19, 2015, 7:55pm UTC](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149/8 "2015-03-19T19:55:49Z")

</div>

I did the same as Vlevo and used move. It worked just fine.

---

<div class="post-metadata">

**Author:** ![Vettax](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vettax/32/1514_2.png) [@Vettax](https://discourse.codecombat.com/u/Vettax)\
**Post date:** [March 19, 2015, 8:30pm UTC](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149/9 "2015-03-19T20:30:47Z")

</div>

Ok, after testing, move seems to get the avantage needed to win. I’m just surprised that in such a simple level to learn command we need such optimisation.  
But totally agree with you about the advantages : no need to reach the coin, and gives order more often. At first sight, I supposed we need to create another loop to use move, but in fact no. If we assume giving order takes no time and giving orders very very often do not slow down soldiers, it’s ok.

---

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/nick/32/784_2.png) [@nick](https://discourse.codecombat.com/u/nick)\
**Post date:** [March 20, 2015, 11:45pm UTC](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149/10 "2015-03-20T23:45:33Z")

</div>

Good points guys; I’ve noted in sample code that you need to use move, not moveXY, or you can’t continuously command your troops.

---

<div class="post-metadata">

**Author:** ![Vettax](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vettax/32/1514_2.png) [@Vettax](https://discourse.codecombat.com/u/Vettax)\
**Post date:** [March 22, 2015, 9:45am UTC](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149/11 "2015-03-22T09:45:37Z")

</div>

Good point, it will help some beginner coders like me 🙂

---

<div class="post-metadata">

**Author:** ![abducktion](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/abducktion/32/1814_2.png) [@abducktion](https://discourse.codecombat.com/u/abducktion)\
**Post date:** [June 23, 2015, 8:26pm UTC](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149/14 "2015-06-23T20:26:29Z")

</div>

Huh. Interesting. I had some trouble on this level using Tharin. I would do fine at first, but once the big ogres came out, they would demolish my troops. I decided to switch to Hattori Hanzo for his extra speed, and I managed to beat the level. I guess I just wasn’t moving/summoning troops fast enough to keep up with the ogres, but when I switched to a slightly faster hero, it worked out fine.

---

<div class="post-metadata">

**Author:** ![Autri\_Basu](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@Autri\_Basu](https://discourse.codecombat.com/u/Autri_Basu)\
**Post date:** [June 29, 2015, 6:05pm UTC](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149/15 "2015-06-29T18:05:03Z")

</div>

I am also having some trouble with this level, as the soldiers are just not attacking. Here is my code:

```python
# Gather coins to summon soldiers and have them attack the enemy.
loop:
    # Move to the nearest coin.
    # Use move instead of moveXY so you can command constantly.
    self.say("I need coins!")
    coins = self.findItems()
    coinIndex = 0
    coin = coins[coinIndex]
    if coin:
        self.move(coin.pos)
    # If you have funds for a soldier, summon one.
    if self.gold > self.costOf("soldier"):
        self.say("I should summon something here!")
        self.summon("soldier")
    enemy = self.findNearest(self.findEnemies())
    if enemy:
        # Loop over all your soldiers and order them to attack.
        soldiers = self.findFriends()
        soldierIndex = 0
        soldier = soldiers[soldierIndex]
        # Use the 'attack' command to make your soldiers attack.
        self.command(soldier, "attack", enemy)

```

---

<div class="post-metadata">

**Author:** ![Vlevo](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vlevo/32/2074_2.png) [@Vlevo](https://discourse.codecombat.com/u/Vlevo)\
**Post date:** [June 29, 2015, 10:30pm UTC](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149/16 "2015-06-29T22:30:11Z")

</div>

Well, when it comes to commanding your soldiers, you don’t do what the comments say to do…

```python
# Loop over all your soldiers and order them to attack.

```

You need to have while loop or a for loop in there, and since it is using “index” I’m assuming this is a “while loop” level.

```python
    if enemy:
        # Loop over all your soldiers and order them to attack.
        soldiers = self.findFriends()
        soldierIndex = 0
        ### while loop command goes here. The previous two lines set it up.
            soldier = soldiers[soldierIndex]
            ### don't forget to increment the index
 
            # Use the 'attack' command to make your soldiers attack.
            self.command(soldier, "attack", enemy)

```

---

<div class="post-metadata">

**Author:** ![lazerA.Y](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@lazerA.Y](https://discourse.codecombat.com/u/lazerA.Y)\
**Post date:** [November 29, 2015, 9:09pm UTC](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149/17 "2015-11-29T21:09:53Z")

</div>

Lol, I just made my hero attack the enemies and I won!

---

<div class="post-metadata">

**Author:** ![Igor\_Galeev](https://avatars.discourse-cdn.com/v4/letter/i/ad7895/32.png) [@Igor\_Galeev](https://discourse.codecombat.com/u/Igor_Galeev)\
**Post date:** [December 4, 2015, 8:15am UTC](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149/18 "2015-12-04T08:15:00Z")

</div>

Hi!  
For _‘‘summon’’_ and the order to _‘‘attack’’_ try to use the design ‘if-else’.

like this:  
…  
**if** (this.gold \> this.costOf(“soldier”)) {  
this.summon(“soldier”);  
} **else if** (enemy) {  
…  
This will make the code easier and easier.  
Hero is not necessarily help in the attack.

---

<div class="post-metadata">

**Author:** ![zap](https://avatars.discourse-cdn.com/v4/letter/z/f6c823/32.png) [@zap](https://discourse.codecombat.com/u/zap)\
**Post date:** [December 19, 2015, 5:38pm UTC](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149/19 "2015-12-19T17:38:10Z")

</div>

I still can’t figure out how to do it. Can you give me the code?

---

<div class="post-metadata">

**Author:** ![zap](https://avatars.discourse-cdn.com/v4/letter/z/f6c823/32.png) [@zap](https://discourse.codecombat.com/u/zap)\
**Post date:** [December 19, 2015, 5:41pm UTC](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149/20 "2015-12-19T17:41:55Z")

</div>

I can’t figure out how to do it. I think I’ve go the code right but it says hero placeholder needs something to command. I get what it means, but for a beginner coder like me, I can’t figure it our. I tried soldier1 soldierIndex1 and a few other things. Here’s my code:

```python
loop:
    # Move to the nearest coin.
    # Use move instead of moveXY so you can command constantly.
    self.say("I need coins!")
    coins = self.findItems()
    coinIndex = 0
    coin = coins[coinIndex]
    if coin:
        self.move(coin.pos)
    # If you have funds for a soldier, summon one.
    if self.gold > self.costOf("soldier"):
        self.say("I should summon something here!")
        self.summon("soldier")
    enemy = self.findNearest(self.findEnemies())
    if enemy:
        # Loop over all your soldiers and order them to attack.
        soldiers = self.findFriends()
        soldierIndex = 0
        
        soldier = soldiers[soldierIndex]
            ### don't forget to increment the index
 
            # Use the 'attack' command to make your soldiers attack.
        self.command(soldier, "attack", enemy)

```

---

<div class="post-metadata">

**Author:** ![ChronistGilver](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chronistgilver/32/3778_2.png) [@ChronistGilver](https://discourse.codecombat.com/u/ChronistGilver)\
**Post date:** [December 19, 2015, 5:51pm UTC](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149/21 "2015-12-19T17:51:59Z")

</div>

Hello, zap, and welcome. Please read the FAQ before posting again. It is essential that you learn how to format your code properly. I have done it for you this time, but do so yourself in the future.

Are you reading the comments at all? It says to “Loop over all your soldiers and order them to attack”, but I see no while-loop or for-loop. It also says to increment the index, but you do not do it. Fix these errors, then come back if you still have problems.

---

<div class="post-metadata">

**Author:** ![zap](https://avatars.discourse-cdn.com/v4/letter/z/f6c823/32.png) [@zap](https://discourse.codecombat.com/u/zap)\
**Post date:** [January 5, 2016, 1:09am UTC](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149/22 "2016-01-05T01:09:05Z")

</div>

I think I’ve fixed it but it still says the same thing Hero placeholder…, here’s my code:

# Gather coins to summon soldiers and have them attack the enemy.

loop:  
# Move to the nearest coin.  
# Use move instead of moveXY so you can command constantly.  
self.say(“I need coins!”)

```
# If you have funds for a soldier, summon one.
if self.gold > self.costOf("soldier"):
    self.say("I should summon something here!")
    self.summon("soldier")
    soldiers = self.findFriends()
    soldierIndex = 0
    soldier = soldiers[soldierIndex]
    soldier = soldier + 1
enemy = self.findNearest(self.findEnemies())
elif soldier:
    
    if enemy:
    
        loop:
        # Loop over all your soldiers and order them to attack.
            soldiers = self.findFriends()
            soldierIndex = 0
            soldier = soldiers[soldierIndex]
            
    # Use the 'attack' command to make your soldiers attack.
    #self.command(soldier, "attack", enemy)
            self.command(soldiers, "attack", enemy)
```

[Next page](https://discourse.codecombat.com/t/level-mountain-mercenaries/3149.md?page=2)
