[SOLVED] Need help on Clash Of Clones ASAP

I have been trying for ages.
I have copyed the .py at master code.
I have looked at loads of other topics for help and I still can’t do it!
Can anyone help me with this?
CODE:
hero.moveXY(68, 78)
back = 0
while True:
enemys = hero.findEnemies()
index = 0
closest_soldier = None
soldier_dist = 999
closest_archer = None
archer_dist = 999
closest = None
dist = 999
while(index<len(enemys)):
distance = hero.distanceTo(enemys[index])
if(enemys[index].health>0 and enemys[index].type != “sand-yak” ):
if(enemys[index].type == ‘archer’ and distance<archer_dist):
archer_dist=distance
closest_archer = enemys[index]
if(enemys[index].type == ‘soldier’ and distance<soldier_dist):
soldier_dist=distance
closest_soldier = enemys[index]
if(distance<dist):
soldier_dist=dist
closest = enemys[index]
index +=1
if(closest_soldier and soldier_dist<10):
enemy = closest_soldier
elif(closest_archer and archer_dist<20):
enemy = closest_archer
else:
enemy = closest
if(enemy):
if(hero.health<hero.maxHealth/2.5 and back==0):
hero.moveXY(40, 85)
back = 1
elif(hero.health<hero.maxHealth/5 and back==1):
hero.moveXY(40, 85)
back = 2
elif(self.isReady(“cleave”)):
self.cleave(enemy)
elif(hero.isReady(“shield”)):
hero.shield()
elif(hero.isReady(“bash”(hero.findNearestEnemy()))):
hero.shield()
else:
self.attack(enemy)
P.S.
mixing self. + hero. does work!

how do i make the spaces appear?

The button </> in the tool bar will set you up for the pre-formatted text, shortcut is (Ctrl + Shift + C). Or just enter the back tick yourself three times (key is left of the 1) before the first line of code and after.

type or paste code here

Then copy/paste your code from the level in between the back tick lines.

In order for us to help you, you must format your code properly!
you can do this by pressing the “</>” button or by typing this formation

19%20AM

hero.moveXY(68, 78)
back = 0
while True:
    enemys = hero.findEnemies()
    index = 0
    closest_soldier = None
    soldier_dist = 999
    closest_archer = None
    archer_dist = 999
    closest = None
    dist = 999
    while(index<len(enemys)):
        distance = hero.distanceTo(enemys[index])
        if(enemys[index].health>0 and enemys[index].type != "sand-yak" ):
            if(enemys[index].type == 'archer' and distance<archer_dist):
                archer_dist=distance
                closest_archer = enemys[index]
            if(enemys[index].type == 'soldier' and distance<soldier_dist):
                soldier_dist=distance
                closest_soldier = enemys[index]
            if(distance<dist):
                soldier_dist=dist
                closest = enemys[index]
        index +=1
    if(closest_soldier and soldier_dist<10):
        enemy = closest_soldier
    elif(closest_archer and archer_dist<20):
        enemy = closest_archer
    else:
        enemy = closest
    if(enemy):
        if(hero.health<hero.maxHealth/2.5 and back==0):
            hero.moveXY(40, 85)
            back = 1
        elif(hero.health<hero.maxHealth/5 and back==1):
            hero.moveXY(40, 85)
            back = 2
        elif(self.isReady("cleave")):
            self.cleave(enemy)
        elif(hero.isReady("shield")):
            hero.shield()
        elif(hero.isReady("bash"(hero.findNearestEnemy()))):
            hero.shield()
        else:
            self.attack(enemy)

Not a master coder or anything, but I did notice this
51%20PM
telling it to shield when bash is ready

thanks! @Thatguy_youknow0
i still keep dieing though.
a have tryed a tip where you don’t use your strongest weapon and armour
and tried to bash instead of useing a sword but that doesn’t work either

Be careful using shield in the middle of an if - elif chain. Shield does not have a cool-down period and will always run. Which means you are never attacking. Something to consider, use the shield when your health is low and you won’t be attacking.
Using hero.findNearest(enemyList) will simplify all of your closest code.

enemy_soldiers = hero.findByType("soldier", hero.findEnemies())
soldier_target = hero.findNearest(enemy_soldiers)

Using special abilities is where you can get ahead on this level. Your enemy has your same gear, but doesn’t know how to use them all. Chain-lightning (Emperor’s Gloves) is an effective attack if you don’t hit the sand-yaks with the chain. Some rings that don’t give inherent abilities help too: Precious for invisibility spell, Ring of Earth for earthskin spell, Steel Ring for electrocute spell. Traps and caltrops could be used too if you understand the risk to your own team. Do you have any pets? Some of them can distract the enemy.

If you take out the enemy minions quickly, the rest of your team will focus their attack on the primary enemy.

Sorry, just a quick sidenote for the future, please could you not post a post which is almost identical to one that has just been posted e.g.

It is unnecessary and creates clutter.
Thanks
Danny

1 Like

thanks for help!
i still keep dieing in the top-left-ish corner and being killed by my clone (i think)
any other tips you can give?

What special abilities do you have available to you now? The Chain-lightning from the Emperor’s glove is very effective on this level. Considering you are matched evenly to begin with and then have to fight some extra ogres, the special attacks or spells are the best way you can win this level.

If you don’t have any special abilities, try to keep some archers alive and then use flags to run around distracting the enemies to let the archers take them out slowly. Don’t attack unless you have a special ability available or have significantly higher health.

@brooksy125

I tried your advice but now my hero doesn’t attack what so ever!
What’s going on?

I’ll have to see your updated code to see what is happening. Which flag are you using?

Some possible culprits:

  1. There is a loop happening where you don’t want it
  2. An if - elif - else chain may be limiting what code is running
  3. Code linked to the flag movements prevents other code
self.moveXY(66, 57)
back = 0
while True:
    enemys = self.findEnemies()
    index = 0
    closest_soldier = None
    soldier_dist = 999
    closest_archer = None
    archer_dist = 999
    closest = None
    dist = 999
    while(index<len(enemys)):
        distance = self.distanceTo(enemys[index])
        if(enemys[index].health>0 and enemys[index].type != "sand-yak" ):
            if(enemys[index].type == 'archer' and distance<archer_dist):
                archer_dist=distance
                closest_archer = enemys[index]
            if(enemys[index].type == 'soldier' and distance<soldier_dist):
                soldier_dist=distance
                closest_soldier = enemys[index]
            if(distance<dist):
                soldier_dist=dist
                closest = enemys[index]
        index +=1
    if(closest_soldier and soldier_dist<10):
        enemy = closest_soldier
    elif(closest_archer and archer_dist<20):
        enemy = closest_archer
    else:
        enemy = closest
    if(enemy):
        if(self.health<self.maxHealth/2.5 and back==0):
            self.moveXY(40, 85)
            back = 1
        elif(self.health<self.maxHealth/5 and back==1):
            self.moveXY(40, 85)
            back = 2
        elif(self.isReady("jump") and self.distanceTo>15):
            self.jumpTo(enemy.pos)
        elif(self.isReady("bash")):
            self.bash(enemy)
        elif(self.isReady("cleave")):
            self.cleave(enemy)
        else:
            self.attack(enemy)

I have just purchased the boots of leaping so the hero.jump works
Here's my gear...

![52|307x425](upload://u7GXdkjhBgaAtqvGwzR8vhT6Eza.png) 

I have tried the tip where you don't use the strongest armour/weapon and that didn't work for me

Why didn’t my image pop up?

Close out the code with the back ticks ``` to switch back to regular comments.

else:
self.attack(enemy)
# did not add closing back ticks
comments

vs (start and end with back ticks with code in the middle) period is a place holder to prevent the formatting
.```

else:
self.attack(enemy)

.```
comments

I noticed that this line is messing up your soldier_dist variable so you won’t ever attack the soldiers.

            if(distance<dist):
                soldier_dist=dist # assigning wrong value to wrong variable

52
I only have a pet because of a Glitch I did

I see you have a command for cleave, but don’t have the sword that can cleave. You need the Long Sword equipped to cleave.

        elif(self.isReady("cleave")):
            self.cleave(enemy)

Using your gear (except the Long Sword) and the flags tactic, I was able to beat the level with a few minor modifications to your code.

Since I used the flags to move the hero around, I removed your move code and just made him shield if I wasn’t having him move unless the special attacks were available. Keep in mind, you have to click submit to use the flags live. It may take a few times to figure out where to move to survive, but it can be done. Key idea is keep your archers alive and be the decoy while they kill everyone else while you run around and shield.

@brooksy125
Thanks so much :laughing:
I will try that and hope that I can finally move onto the Mountain World!:mountain::mountain: