[SOLVED] Ring Bearer Please Help

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

// This function does the math to determine the offset a soldier should stand at.
function radialToCartesian(radius, degrees) {
    var radians = Math.PI / 180 * degrees;
    var xOffset = radius * Math.cos(radians);
    var yOffset = radius * Math.sin(radians);
    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.

What map is this? Please give any other additional information about errors and etc.

1 Like

https://codecombat.com/play/level/ring-bearer?

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. :grin: (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.

Sorry we cant give answers

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 :grin:

2 Likes

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

Then you wouldn’t learn anything. Give us your code and we can help you.

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;
return radialToCartesian(5, angle);
}
function radialToCartesian(radius, degrees) {
var radians = Math.PI / 180 * degrees;
var xOffset = radius * Math.cos(radians);
var yOffset = radius * Math.sin(radians);
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});

}

Look at this and please try and write your own code.

Stop being rude and listen to the rules.

2 Likes

can u give me code pls. I might get bad grade in school :frowning:

Well sorry I don’t do JavaScript and again no we can’t give you the code.

2 Likes