Clash of Clones - Stuck


I’m very stuck in Clash of Clones and I’m not sure how to solve it. I tried different ways but nothing seems to be working.

In the last iteration, I wanted to use “chain-lightning” which it works, but I’m having an issue where the hero says “but it’s dead”. I think what’s happening is that when I use the chain-lightning, I’m killing multiiple enemies, so my enemyIndext gets thrown off, so he’s trying to kill someone that’s already dead. I’m not quite sure how to fix that. Any ideas?

This is my code.

def attackArchers():
    enemies = hero.findByType("archer", hero.findEnemies())
    archerIndex = 0
    if enemies:
        archer = enemies[archerIndex]
        while archerIndex < len(enemies):
            killed = []
            if hero.canCast("chain-lightning", archer):
                hero.cast("chain-lightning", archer)
                enemies = hero.findByType("archer", hero.findEnemies())
        archerIndex += 1
            # enemies = hero.findByType("archer", hero.findEnemies())

while True:

I think the best thing to do would be to use something like this:

length = len(enemies)
[cast chain lightning]
newLength = len(enemies)
enemyIndex += length - newLength

I’m not sure how well that exact code would work, but hopefully you get the general idea of it.

1 Like

Makes sense… I was trying to do something similar, but I don’t think I managed to solve it. Let me give it a try with your idea.

Thank you