# \[Solved\] Clash of clones python

**URL:** <https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505>\
**Category:** Solved\
**Created:** [August 12, 2018, 11:17am UTC](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505 "2018-08-12T11:17:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![starwars72015](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/starwars72015/32/10136_2.png) [@starwars72015](https://discourse.codecombat.com/u/starwars72015)\
**Post date:** [August 12, 2018, 11:17am UTC](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505/1 "2018-08-12T11:17:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![starwars72015](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/starwars72015/32/10136_2.png) [@starwars72015](https://discourse.codecombat.com/u/starwars72015)\
**Post date:** [August 12, 2018, 11:18am UTC](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505/2 "2018-08-12T11:18:18Z")

</div>

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)
```

---

<div class="post-metadata">

**Author:** ![SuperSmacker](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/supersmacker/32/8385_2.png) [@SuperSmacker](https://discourse.codecombat.com/u/SuperSmacker)\
**Post date:** [August 12, 2018, 2:12pm UTC](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505/3 "2018-08-12T14:12:40Z")

</div>

> [@starwars72015](#):
>
> to help people who are stuck on clash of clones code combat like me

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

---

<div class="post-metadata">

**Author:** ![starwars72015](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/starwars72015/32/10136_2.png) [@starwars72015](https://discourse.codecombat.com/u/starwars72015)\
**Post date:** [August 12, 2018, 4:43pm UTC](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505/4 "2018-08-12T16:43:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Not\_a\_User](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/not_a_user/32/8834_2.png) [@Not\_a\_User](https://discourse.codecombat.com/u/Not_a_User)\
**Post date:** [August 12, 2018, 4:43pm UTC](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505/5 "2018-08-12T16:43:52Z")

</div>

have you tried shielding?

---

<div class="post-metadata">

**Author:** ![Not\_a\_User](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/not_a_user/32/8834_2.png) [@Not\_a\_User](https://discourse.codecombat.com/u/Not_a_User)\
**Post date:** [August 12, 2018, 4:44pm UTC](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505/6 "2018-08-12T16:44:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![starwars72015](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/starwars72015/32/10136_2.png) [@starwars72015](https://discourse.codecombat.com/u/starwars72015)\
**Post date:** [August 12, 2018, 4:45pm UTC](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505/7 "2018-08-12T16:45:35Z")

</div>

here is my new code  
it kills all the archers

---

<div class="post-metadata">

**Author:** ![starwars72015](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/starwars72015/32/10136_2.png) [@starwars72015](https://discourse.codecombat.com/u/starwars72015)\
**Post date:** [August 12, 2018, 4:46pm UTC](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505/8 "2018-08-12T16:46:50Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![starwars72015](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/starwars72015/32/10136_2.png) [@starwars72015](https://discourse.codecombat.com/u/starwars72015)\
**Post date:** [August 12, 2018, 4:47pm UTC](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505/9 "2018-08-12T16:47:24Z")

</div>

i tried shielding but it just got worse

---

<div class="post-metadata">

**Author:** ![Not\_a\_User](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/not_a_user/32/8834_2.png) [@Not\_a\_User](https://discourse.codecombat.com/u/Not_a_User)\
**Post date:** [August 12, 2018, 4:47pm UTC](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505/10 "2018-08-12T16:47:27Z")

</div>

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

```python
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)

```

---

<div class="post-metadata">

**Author:** ![starwars72015](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/starwars72015/32/10136_2.png) [@starwars72015](https://discourse.codecombat.com/u/starwars72015)\
**Post date:** [August 12, 2018, 4:48pm UTC](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505/11 "2018-08-12T16:48:07Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Not\_a\_User](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/not_a_user/32/8834_2.png) [@Not\_a\_User](https://discourse.codecombat.com/u/Not_a_User)\
**Post date:** [August 12, 2018, 4:48pm UTC](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505/12 "2018-08-12T16:48:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![starwars72015](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/starwars72015/32/10136_2.png) [@starwars72015](https://discourse.codecombat.com/u/starwars72015)\
**Post date:** [August 12, 2018, 4:48pm UTC](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505/13 "2018-08-12T16:48:40Z")

</div>

sorry give me a second

---

<div class="post-metadata">

**Author:** ![Not\_a\_User](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/not_a_user/32/8834_2.png) [@Not\_a\_User](https://discourse.codecombat.com/u/Not_a_User)\
**Post date:** [August 12, 2018, 4:49pm UTC](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505/14 "2018-08-12T16:49:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Not\_a\_User](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/not_a_user/32/8834_2.png) [@Not\_a\_User](https://discourse.codecombat.com/u/Not_a_User)\
**Post date:** [August 12, 2018, 4:55pm UTC](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505/15 "2018-08-12T16:55:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![maka](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/maka/32/3261_2.png) [@maka](https://discourse.codecombat.com/u/maka)\
**Post date:** [August 17, 2018, 2:11pm UTC](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505/16 "2018-08-17T14:11:36Z")

</div>

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.

```python
if enemy:
    doThing()

```

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

---

<div class="post-metadata">

**Author:** ![starwars72015](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/starwars72015/32/10136_2.png) [@starwars72015](https://discourse.codecombat.com/u/starwars72015)\
**Post date:** [August 18, 2018, 6:41am UTC](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505/17 "2018-08-18T06:41:49Z")

</div>

i changed my code and finished the level

---

<div class="post-metadata">

**Author:** ![starwars72015](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/starwars72015/32/10136_2.png) [@starwars72015](https://discourse.codecombat.com/u/starwars72015)\
**Post date:** [August 18, 2018, 6:42am UTC](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505/18 "2018-08-18T06:42:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JEFF](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jeff/32/11761_2.png) [@JEFF](https://discourse.codecombat.com/u/JEFF)\
**Post date:** [April 3, 2020, 2:41pm UTC](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505/19 "2020-04-03T14:41:05Z")

</div>

What was the finished code that won the level

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [April 3, 2020, 2:48pm UTC](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505/20 "2020-04-03T14:48:30Z")

</div>

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:

> [@\[Essentials\] How To Post/Format Your Code Correctly](https://discourse.codecombat.com/t/essentials-how-to-post-format-your-code-correctly/15521):
>
> Formatting your code before posting code is essential to our community, and if you don’t we might not be able to help frowning Everyone must know how to format ALL of your code properly. It’s really easy and only requires a very small amount of effort. To post your code from the game , use the \</\> button or it won’t format properly. When you click the \</\> button, the following will appear: Please paste ALL …

Thanks  
Danny

[Next page](https://discourse.codecombat.com/t/solved-clash-of-clones-python/15505.md?page=2)
