``````function findSoldierOffset(soldiers, i) {
var soldier = soldiers[i];
var angle = i * 360 / soldiers.length;
}

// This function does the math to determine the offset a soldier should stand at.
var radians = Math.PI / 180 * degrees;
return {x: xOffset, y: yOffset};
}
var peasant = hero.findByType("peasant")[0];
// Use findByType to get an array of your soldiers.
while(true) {
// Use a for-loop to iterate over your array of soldiers.
var soldiers = hero.findByType("soldier");
for(var i = 0; i < soldiers.length; i ++) {
var soldier = soldiers[i];
var offset = findSoldierOffset(soldiers, i);
var offsetX = peasant.pos.x + offset.x;
var offsetY = peasant.pos.y + offset.y;
var position = {"x": offsetY, "y": offsetY};
hero.command(soldier, "move", position);

}
// Find the offset for a soldier.
// Add the offset.x and offset.y to the peasant's pos.x and pos.y.
// Command the soldier to move to the new offset position.
// The hero should keep pace with the peasant!
hero.move({x: hero.pos.x + 0.2, y: hero.pos.y});
}
``````

So the problem is that the soldiers are stop moving in the middle.

1 Like
1 Like

Itâ€™s in cloudrip mountain.

3 Likes

The soldiers always stops in the middle. And I have no idea why.

1 Like

These lines arenâ€™t needed, you can put these on one line. Use your `var position` to store the `peasant.pos.x + offset.x` and the `peasant.pos.y + offset.y` in the `var position` and command your soldier to move to â€śpositionâ€ť apart from that your code is right.

Maan!
You rock!
Thank you.

1 Like

My pleasure. (20 chars)

1 Like

What is the final solution to the level? Whats the whole code look like?

We donâ€™t give out working code, also welcome to the forums. We also donâ€™t revive â€śdead topicsâ€ť

Welcome to the forum. We can not give solutions but if you need help you can make a new topic.

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!

wow all of us posted at the same time

2 Likes

bruh i need it for school. can you just give me the code to complete the level ?

Im running out of time but i tried to complete the level. I need to complete it for school

function findSoldierOffset(soldiers, i) {
var soldier = soldiers[i];
var angle = i * 360 / soldiers.length;
}
var radians = Math.PI / 180 * degrees;
return {x: xOffset, y: yOffset};
}

var peasant = hero.findByType(â€śpeasantâ€ť)[0];

while(true) {

`````` var soldiers = hero.findByType("soldier");
for(var i = 0; i < soldiers.length; i ++) {

var soldier = soldiers[i];
var offset = findSoldierOffset(soldiers, i);
var x = offset.x + peasant.pos.x;
var y = offset.y + peasant.pos.y;
hero.command(soldiers, "move", {'x': x, 'y': y});
}
hero.move({x: hero.pos.x + 0.2, y: hero.pos.y});
``````

}