[Solved] Clash of clones python

to help people who are stuck on clash of clones code combat like me

here is my code pls help:
while True:
enemyIndex = 0
enemies = self.findEnemies()
while enemyIndex < len(enemies) and self.health > self.maxHealth / 4:
enemy = enemies[enemyIndex]
enemyIndex += 1
if enemy.type != ‘sand-yak’:
while enemy.health > 0:
if self.isReady(“electrocute”):
hero.electrocute(enemy)
if self.isReady(“bash”):
hero.bash(enemy)
if self.isReady(“cleave”):
hero.cleave(enemy)
else:
self.attack(enemy)
if self.health <= self.maxHealth / 4:
enemy = enemies[enemyIndex]
enemy=hero.findNearestEnemy()
distance=hero.distanceTo(enemy)
enemyIndex += 1
while enemy.health>0 :

        if distance < 4:
            if self.isReady("cleave"):
                self.cleave(enemy)
            else:
                self.attack(enemy)
        else:
            self.attack(enemy)

So are you posting a solution? If so please remove.

If not, (since you said pls help under that so idk whether you’re posting a solution or you need help with your code)

Please follow the Community Guidelines and post the code in a beautifully formatted fashion tyvm

it is not a solution it is just that i need help

have you tried shielding?

and I suggest not using your amazing armor because then the clone has it. I also suggest that if you have more abilities, use them

here is my new code
it kills all the archers

while True:
enemyIndex = 0
enemies = self.findEnemies()
while enemyIndex < len(enemies) and self.health > self.maxHealth / 4:
enemy = enemies[enemyIndex]
enemyIndex += 1
if enemy.type != ‘sand-yak’:
while enemy.health > 0:
if self.isReady(“electrocute”):
hero.electrocute(enemy)
if self.isReady(“bash”):
hero.bash(enemy)
if self.isReady(“cleave”):
hero.cleave(enemy)
if self.isReady(“power up”):
self.powerUp()
else:
self.attack(enemy)
if self.health <= self.maxHealth / 4:
enemy = enemies[enemyIndex]
enemy=hero.findNearestEnemy()
distance=hero.distanceTo(enemy)
enemyIndex += 1
while enemy.health>0 :
if distance < 4:
if self.isReady(“cleave”):
self.cleave(enemy)
else:
self.attack(enemy)
else:
self.attack(enemy)

i tried shielding but it just got worse

please format your code, I have done it for you this time

while True:
enemyIndex = 0
enemies = self.findEnemies()
while enemyIndex < len(enemies) and self.health > self.maxHealth / 4:
enemy = enemies[enemyIndex]
enemyIndex += 1
if enemy.type != ‘sand-yak’:
while enemy.health > 0:
if self.isReady(“electrocute”):
hero.electrocute(enemy)
if self.isReady(“bash”):
hero.bash(enemy)
if self.isReady(“cleave”):
hero.cleave(enemy)
if self.isReady(“power up”):
self.powerUp()
else:
self.attack(enemy)
if self.health <= self.maxHealth / 4:
enemy = enemies[enemyIndex]
enemy=hero.findNearestEnemy()
distance=hero.distanceTo(enemy)
enemyIndex += 1
while enemy.health>0 :
if distance < 4:
if self.isReady(“cleave”):
self.cleave(enemy)
else:
self.attack(enemy)
else:
self.attack(enemy)

ok
while True:
enemyIndex = 0
enemies = self.findEnemies()
while enemyIndex < len(enemies) and self.health > self.maxHealth / 4:
enemy = enemies[enemyIndex]
enemyIndex += 1
if enemy.type != ‘sand-yak’:
while enemy.health > 0:
if self.isReady(“electrocute”):
hero.electrocute(enemy)
if self.isReady(“bash”):
hero.bash(enemy)
if self.isReady(“cleave”):
hero.cleave(enemy)
if self.isReady(“power up”):
self.powerUp()
else:
self.attack(enemy)
if self.health <= self.maxHealth / 4:
enemy = enemies[enemyIndex]
enemy=hero.findNearestEnemy()
distance=hero.distanceTo(enemy)
enemyIndex += 1
while enemy.health>0 :
if distance < 4:
if self.isReady(“cleave”):
self.cleave(enemy)
else:
self.attack(enemy)
else:
self.attack(enemy)

To format, use triple backticks above and below your code,

sorry give me a second

but my question is, do you really need to slow down your enemies if you are going into their range anyways?

what items are you using also, it might be an equipment issue

Take a look around the forum, there are several topics on Clash of Clones already.

It is not your equipment. This level is not about equipment, but about being clever.

Your enemy hero has all the same equipment as you, but your enemy hero doesn’t know how to use any special abilities. You do – so use them in clever ways.

Also, when you post code, use three backticks (the character on the key to the left of the 1 on most English keyboards) before and after your code so it is properly formatted.

if enemy:
    doThing()

The code you’ve posted has no tabs/spacing, which means it won’t work.

1 Like

i changed my code and finished the level

that was a few day ago the i finished the level but thanks for the comments

What was the finished code that won the level

Hi @JEFF, welcome to the CodeCombat Discourse.
We don’t share solutions here, as it’s not the purpose of the forum and can ruin the game for some people. Instead, if you need help with your code, please post it onto the forum.
To learn how to post your code onto the forum formatted (with indents) read this topic:

Thanks
Danny