Python: Steelclaw Gap

It wants me to use a better target for “defend”


# This level introduces the % operator, also known as the modulo operator.
# a % b returns the remainder of a divided by b
# This can be used to wrap around to the beginning of an array when an index might be greater than the length
defendPoints = [{"x": 35, "y": 63},{"x": 61, "y": 63},{"x": 32, "y": 26},{"x": 64, "y": 26}]
summonTypes = ["soldier","soldier","soldier","soldier","archer","archer","archer","archer"]
# You start with 360 gold to build a mixture of soldiers and archers.
# self.built is an array of the troops you have built, ever.
# Here we use "len(self.built) % len(summonTypes)" to wrap around the summonTypes array
def summonTroops():
    type = summonTypes[len(hero.built) % len(summonTypes)]
    if hero.gold >= hero.costOf(type):
        hero.summon(type)
def commandTroops():
    friends = hero.findFriends()
    for i in range(len(friends)):
        friend = friends[i]
        # Use % to wrap around defendPoints based on friendIndex
        defendPoints % friend
        # Command your minion to defend the defendPoint
        hero.command(friend, "defend", defendPoints)
while True:
    summonTroops()
    commandTroops()
1 Like

I also have almost no idea what’s going on with the percent sign.

1 Like

try doing this defendPoint = defendPoints[i%len(defendPoints) ] instead of this

Otherwise your code is right

1 Like

It still doesn’t like my command line.

# This level introduces the % operator, also known as the modulo operator.
# a % b returns the remainder of a divided by b
# This can be used to wrap around to the beginning of an array when an index might be greater than the length
defendPoints = [{"x": 35, "y": 63},{"x": 61, "y": 63},{"x": 32, "y": 26},{"x": 64, "y": 26}]
summonTypes = ["soldier","soldier","soldier","soldier","archer","archer","archer","archer"]
# You start with 360 gold to build a mixture of soldiers and archers.
# self.built is an array of the troops you have built, ever.
# Here we use "len(self.built) % len(summonTypes)" to wrap around the summonTypes array
def summonTroops():
    type = summonTypes[len(hero.built) % len(summonTypes)]
    if hero.gold >= hero.costOf(type):
        hero.summon(type)
def commandTroops():
    friends = hero.findFriends()
    for i in range(len(friends)):
        friend = friends[i]
        # Use % to wrap around defendPoints based on friendIndex
        defendPoints = defendPoints[i%len(defendPoints)
        # Command your minion to defend the defendPoint
        hero.command(friend, "defend", defendPoints)
while True:
    summonTroops()
    commandTroops()
1 Like

you have to do hero.command(friend, "defend", defendPoint) now it should work.

1 Like

The only problem was that “s” in Points delete that and you are all good.

1 Like

yeah, still not working…

# This level introduces the % operator, also known as the modulo operator.
# a % b returns the remainder of a divided by b
# This can be used to wrap around to the beginning of an array when an index might be greater than the length
defendPoints = [{"x": 35, "y": 63},{"x": 61, "y": 63},{"x": 32, "y": 26},{"x": 64, "y": 26}]
summonTypes = ["soldier","soldier","soldier","soldier","archer","archer","archer","archer"]
# You start with 360 gold to build a mixture of soldiers and archers.
# self.built is an array of the troops you have built, ever.
# Here we use "len(self.built) % len(summonTypes)" to wrap around the summonTypes array
def summonTroops():
    type = summonTypes[len(hero.built) % len(summonTypes)]
    if hero.gold >= hero.costOf(type):
        hero.summon(type)
def commandTroops():
    friends = hero.findFriends()
    for i in range(len(friends)):
        friend = friends[i]
        # Use % to wrap around defendPoints based on friendIndex
        defendPoint = defendPoints[i%len(defendPoints)
        # Command your minion to defend the defendPoint
        hero.command(friend, "defend", defendPoint)
while True:
    summonTroops()
    commandTroops()

1 Like

@CocoCharlie you’re missing a closing square bracket ] at the end of

defendPoint = defendPoints[i%len(defendPoints)

You need to look at these things very carefully I told you how to do it here @CocoCharlie

This is solved now I believe(can you mark the post that helped you solve your problem CocoCharlie and change the title).

you don’t know if he solved it yet don’t rush him.

It worked! thanks guys! to honest I saw that bracket and deleted it lol.

lol i always forget to change the title.

Happens to me too. Did you get the Bonus @CocoCharlie?

ah, no. But I feel like you need to write a bunch of your own code, and my minds being blown enough already. :wink:
~Andrew

I actually told you based off how i got the bonus so you should have gotten it(if you did not submit it again).

An archer at the bottom-left corner dies at the end. :disappointed_relieved:

submit again it should work I did it with the exact same code.

the soldiers get stuck behind the archers.

That is normal happened to me and I got the bonus submit until it works