Clash of Clones Help!

Ok, I’ll try. (20 characters)

1 Like

I can’t get the flags to work, this is my code for flags:

while True:
    flag = hero.findFlag()
    if flag:
        flagPos = flag.pos
        flagX = flagPos.x
        flagY = flagPos.y
        flag = hero.findFlag("green")
    self.moveXY(flagX, flagY)
    self.pickUpFlag(flag)

ok so I did do what you ask but I doesn’t work still, here is my full code (NO FLAG CODE INCLUDED):

while True:
    enemyIndex = 0
    enemies = self.findNearestEnemy()
    while enemyIndex < len(enemies):
        enemy = enemies[enemyIndex]
        enemyIndex += 1
        if enemy.type != 'sand-yak':
            while enemy.health > 0:
                if self.isReady("bash"):
                    hero.bash(enemy)
                if self.isReady("cleave"):
                    hero.cleave(enemy)
                if self.isReady("build"):
                    hero.buildXY("bear-trap", enemy.pos.x, enemy.pos.y)
                else:
                    self.attack(enemy)
    if self.health <= self.maxHealth:
        enemy = hero.findNearestEnemy()
        distance=hero.distanceTo(enemy)
        while enemy.health > 0 :
            if distance < 4:
                if self.isReady("cleave"):
                    self.cleave(enemy)
                if self.health < self.maxHealth / 3:
                    hero.shield()
                else:
                    self.attack(enemy)
            else:
                self.attack(enemy)
            if self.health < self.maxHealth / 5:
                hero.shield()

This is the first error I’ve found, this may be causing all the problems. You use self.findNearestEnemy(), that will only find you one enemy: the nearest one. You want a command which will find you an array of multiple enemies. (findEnemies()…)
Ah I’ve just seen where you went from that to nearest. Sorry for the misunderstanding.

I meant you should just use if enemy:, with the nearest enemy. You really don’t need to loop through enemies to attack them. There’s no need. Just find the nearest, check if it exists, then run the rest of your attack code.
Danny

Helps A LOT But it is still not working, Code:

while True:
    enemyIndex = 0
    enemies = self.findEnemies()
    while enemyIndex < len(enemies):
        enemy = enemies[enemyIndex]
        enemyIndex += 1
        if enemy.type != 'sand-yak':
            while enemy.health > 0:
                if self.isReady("bash"):
                    hero.bash(enemy)
                if self.isReady("cleave"):
                    hero.cleave(enemy)
                if self.isReady("build"):
                    hero.buildXY("bear-trap", enemy.pos.x, enemy.pos.y)
                else:
                    self.attack(enemy)
    if self.health <= self.maxHealth:
        enemy = hero.findNearestEnemy()
        distance=hero.distanceTo(enemy)
        while enemy.health > 0 :
            if distance < 4:
                if self.isReady("cleave"):
                    self.cleave(enemy)
                if self.health < self.maxHealth / 3:
                    hero.shield()
                else:
                    self.attack(enemy)
            else:
                self.attack(enemy)

(P.S.) now I have 632 gems from daily stuff.

Like I said, you don’t need if hero.isReady()
I find using for loops much easier for enemies or friends, I don’t know if you can use for loops but try it out! I think it is much easier than enemyIndex.
Lydia

Well, you haven’t actually done what I said yet.
Why this:

Instead of this:

enemy = hero.findNearestEnemy()
if enemy:

You code attacks enemies in a specific order which is not good for tactics. Just find the nearest and use that. No loops necessary except for the while True!

Where do you put that? I can’t if a place that says enemy = hero.findNearestEnemy() if enemy:.

talk later, I got to go to online class.

I think you may be overthinking this a little bit. For some reason you’re using a loop to attack. That hasn’t been taught and is not very successful. The traditional way of attacking is finding the nearest enemy. Checking if they exist, then doing stuff like:

if hero.isReady("cleave", enemy):
    hero.cleave(enemy)
else:
    hero.attack(enemy)

Look at earlier levels in the forest if you’re struggling with that.
Danny

Sure (20 characters)

Hello! I have been struggling on the clas of clones level for quite some time now at first I wrote my own code but that failed so I went to google to try and get help, I looked on GitHub and Youtube and this was the code that got me the furthest. But I still can’t complete it. Any help on how I can approve would be great :smile:

self.moveXY(68, 78)
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("power-up")):
            self.powerUp()
            self.attack(enemy)
        elif(self.isReady("cleave")):
            self.cleave(enemy)
        else:
            self.attack(enemy)
1 Like

hmm can i see your gear and gems?

“If at first you don’t succeed, try, try, try again.” (-someone)
Besides, this level is primarily about your gear. My recommendations:

  • not a huge amount of armour, mediocre armour is good. If you use special abilities you will have a damage advantage over your clone. For example if you bashed every now and again you damage advantage would be 500, or whatever the bash damage was (subtracting the DPS of your sword for the time that it took to bash, but that’s quite low) times the amount of times you could use it in the level (maybe 5). So if you have a 400 damage advantage you need to make sure that’s enough to kill your clone (without you being killed). Obviously, using lots of gear will increase that advantage.
  • emperor’s gloves, even if you don’t want to get them just for this level, they’re so good in every other level as well.
  • cleave sword
  • jump boots (only if you want to do something like: jump into middle – cleave (a popular tactic))
  • bash shield
    Danny
2 Likes

To get the right answer, you have to ask the right question
The right question here must be: “What gear must I have to pass the level with the code I have found in the net?”

Hi there, I think @Deadpool198’s answer is very useful, thank you!

My two cents to the topic that might hopefully once and for all help lots of players stuck in this level (but I will intentionally not make the hints too concrete, so that players can still enjoy coding and the trials and errors!):

  1. Recommendations that seem crucial to even get close to a win:
  • Make your clone’s attacks weak by using just a low damage sword. Otherwise it may destroy your allies quickly and then you can only hardly beat all the enemies on your own. (Note that the old trick of not using a sword at all is no longer allowed.)
  • OTOH you still need to have weapons that will enable you to attack efficiently.
  • Note that your enemy is only able to use attack(), while you can also do bash() and other types of attacks to take your enemies down.
  • Choose your attack targets wisely. (Don’t forget you can click on a unit to find out its type and other traits. It’s no secret that archers are a very popular target to attack firstly.)
  • Good enough health. (I myself started with 2k and ended with 800, while still having 6 archers and 2 soldiers at hand after 30s victory. If you choose to run away from time to time, you may spare some good amount of health, I didn’t try that though.)
  1. Optimizations which can help, but maybe they are not crucial (depending on your strategy and gears):
  • Use Long Sword in order to cleave(). The Simple Sword might not be enough (based on my own experience).
  • Use what you’ve learned so far in order to have a proper main loop. Like doing just one small action in every cycle. (You don’t want to lose much health while just moving to a pre-selected distant enemy, for example.)
  • Choose your next attack type wisely. (Remember that you need to wait e. g. for several seconds until the next bash() is available.)
  1. Optimizations that seem purely optional, but still may help:
  • Use Emperor’s Gloves that enable you to cast(). (I don’t have them yet.)
  • Use Jump Boots. (BTW I tried to use them, but there was some weird delay before the jump, so I gave up on them.)

Final note: The level is doable without any subscription, you just maybe need to earn enough gems to get some better gears. If you went through all the previous levels, you should probably have enough of them…

3 Likes

so, i need help with this level too
ive been able to quickly beat the hero clone but i dont have ant way to heal at all to survive any longer
im using obsidian helm and painted breastplate
and using runesword and steel striker plus punch glove
and other stuff
like engraved watch trap belt programmatacon 3 enchanted lenses wood strand quartz sense stone
tarnished copper band adv flags
plz help

Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!

Don't use runesword. It's too strong. And Could you post your code? Formatted?

If you want to beat Clash of Clones, you need to use the weakest possible items with the strongest possible activated skills, to achieve the greatest difference between you and the AI.

1 Like