Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

{SOLVED}Steelclaw gap - friend keeps dying? keeps saying incomplete{SOLVED}


#1

I make it to the 20.7 mark, but 1 archer keeps dying,

# 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
        defPon = defendPoints[i % len(defendPoints)]
        # Command your minion to defend the defendPoint
        hero.command(friend, "defend", defPon)

while True:
    summonTroops()
    commandTroops()

#2

ok, so I submitted it and It says I pass???
but im not getting them to survive for 60 seconds, any ideas?


#3

Please explain what you mean by this. Did you pass or did you not pass? If you did not pass, please send a screenshot and give more information about what is happening when you run your code as well as any errors that come up

Thanks!
-@Luke10


#4

I passed it, I just wanted to get the bonus.
when I ran it, it would say incomplete, however once I submitted it, it said I passed…so I just let it be lol.


#5

:+1: I hope you keep doing well with codecombat!!