Level mountain mercenaries


#1

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.


#2

Let me guess . . . you are using moveXY


#3

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 ?


#4

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.


#5

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?


#6

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.


#7

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.) :wink:


#8

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


#9

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.


#10

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.


#11

Good point, it will help some beginner coders like me :slight_smile:


#14

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.


#15

I am also having some trouble with this level, as the soldiers are just not attacking. Here is 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!")
    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)

#16

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

# 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.

    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)

#17

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


#18

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.


#19

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


#20

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:

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)

#21

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.


#22

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)