Ring bearer help python hero placeholder needs something to command

# You must escort a powerful magical ring back to town to be studied.
# The goal is to escape, not fight. More ogres lurk in the surrounding mountains!
# Make a circle of soldiers around the peasant!
# We give you two functions to help with this:

# findSoldierOffset figures out the position a soldier should stand at in relation to the peasant.
# The first argument 'soldiers' should be an array of your soldiers.
# The second argument 'i' is the index of the soldier (in soldiers) you want to find the position for.
def findSoldierOffset(soldiers, i):
    soldier = soldiers[i]
    angle = i * 360 / len(soldiers)
    return radialToCartesian(5, angle)

# This function does the math to determine the offset a soldier should stand at.
def radialToCartesian(radius, degrees):
    radians = Math.PI / 180 * degrees
    xOffset = radius * Math.cos(radians)
    yOffset = radius * Math.sin(radians)
    return {"x": xOffset, "y": yOffset}
hero.toggleFlowers(True)
hero.setFlowerColor("blue")
peasant = hero.findByType("peasant")[0]
n = 0 
# Use findByType to get an array of your soldiers.
while True:
    friends = hero.findFriends()
    
    # Use a for-loop to iterate over range(len(soldiers)).
    
    soldiers = []
    for friend in friends:
        if friend.type == "soldier":
            soldiers[n] = friend.id
            n += 1
            hero.say("the length of soldiers is " + len(soldiers) + ".")
    # Find the offset for a soldier.
    for i in range(len(soldiers)-1):
        offset = findSoldierOffset(soldiers, i)
        offsetX = peasant.pos.x + offset.x
        offsetY = peasant.pos.y + offset.y
        pos =  {'x': offsetX, 'y': offsetY}
        hero.command(soldiers[i], 'move',pos) #<-- hero placeholder needs something to command.
        
        # Command the soldier to move to the new offset position.
        # Add the offset.x and offset.y to the peasant's pos.x and pos.y.
    # The hero should keep pace with the peasant!
    hero.moveXY(hero.pos.x +.2, hero.pos.y)

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!

So, I’m not good at coding, but I do know of some who are good. And I will call them here. @abc, @Eric_Tang, @098765432123. Hope this helps, and have a great time on the discourse!

2 Likes

I don’t think I can help but can I please have a link to the level?

1 Like

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

Sorry I can’t help, it is a Subscriber level… @Deadpool198 are you able to help?

Can you guys tell me if you don’t want to be summoned by me anymore?

Oh no it is fine I just didn’t know if it was a sub level or not or if I have passed it or not.

I’m also working on this level, and I just figured out the problem with your code: you don’t define soldiers. if you said:

soldiers = hero.findFriends

it would work I think.

never mind, it doesn’t work.

This was from a year ago…

1 Like