Clash of clones/ Stuck/

I have been stuck on this level for weeks and i still can’t pass and i’ve done everything i can to grind up for it but im still to weak

enemy = hero.findNearestEnemy()
enemyDis = hero.distanceTo(enemy)
BuildY = hero.pos.y
item = hero.findNearestItem()


while True:
    enemy = hero.findNearestEnemy()
    if enemy.type != "sand-yak":
        
        if enemy and hero.distanceTo(enemy) == 20:
            hero.moveXY(48, 80)
        elif enemy and hero.distanceTo(enemy) <= 15:
            if hero.isReady("jump"):
                hero.jumpTo(enemy)
            elif hero.isReady("punch"):
                hero.punch(enemy)
            elif hero.isReady("bash"):
                hero.bash(enemy)
            else:
                hero.attack(enemy)
        elif item:
            hero.moveXY(item.pos.x, item.pos.y)
        elif enemy and hero.distanceTo(enemy) <= 10:
            hero.say("Attack!")
            if hero.isReady("jump"):
                hero.jumpTo(enemy)
            elif hero.isReady("punch"):
                hero.punch(enemy)
            elif hero.isReady("sheild"):
                hero.shield
            elif hero.isReady("bash"):
                hero.bash(enemy)
            else:
                hero.attack(enemy)
        elif hero.health <= enemy.health:
            hero.moveXY(36, 62)
            hero.shield()
        else:
            hero.moveXY(36, 62)

Equipment Code combat 4.3.21.PNG

This is the problem. Shielding has no cooldown so it will be stuck there forever. You might also make the bash thing a if instead of elif

Correct me if im wrong but I think you need parenthesis.

That is also another thing.

Yes thank you but i am still to weak

I did and it didn’t change anything

Can you show your new updated code.

enemy = hero.findNearestEnemy()
enemyDis = hero.distanceTo(enemy)
BuildY = hero.pos.y
item = hero.findNearestItem()


while True:
    enemy = hero.findNearestEnemy()
    if enemy.type != "sand-yak":
        
        if enemy and hero.distanceTo(enemy) == 20:
            hero.moveXY(48, 80)
        elif enemy and hero.distanceTo(enemy) <= 15:
            if hero.isReady("jump"):
                hero.jumpTo(enemy)
            elif hero.isReady("punch"):
                hero.punch(enemy)
            if hero.isReady("bash"):
                hero.bash(enemy)
            else:
                hero.attack(enemy)
        elif item:
            hero.moveXY(item.pos.x, item.pos.y)
        elif enemy and hero.distanceTo(enemy) <= 10:
            hero.say("Attack!")
            if hero.isReady("jump"):
                hero.jumpTo(enemy)
            elif hero.isReady("punch"):
                hero.punch(enemy)
            if hero.isReady("bash"):
                hero.bash(enemy)
            else:
                hero.attack(enemy)
        elif hero.health <= enemy.health:
            hero.moveXY(36, 62)
            hero.shield(enemy)
        else:
            hero.moveXY(36, 62)

here it is

Try using the cleave sword and jumping into the midst of the archers at the start, then cleaving, then attacking the enemy hero.
Works for a lot of people.
You could also researching the extensive collection of similar topics to this one (92 to be exact :grin:. I’m sure there’s something in there that can help you):
https://discourse.codecombat.com/search?q=clash%20of%20clones

1 Like

Thanks for the tip Deadpool198. I should have noted the cleave stuff. I can produce that piece of code it you want to.

The clone code is basically a mirror of your equipment and has this code

while True:
    Enemy = hero.findnearestenemy()
    if Enemy:
        hero.attack()

My advise is

use simple sword, and use special moves. Cleave sword is also really good

And for the attack thing you just put hero.attack() instead you should do hero.attack(Enemy)

Like this?
Equipment Code combat 4.3.21

while True:
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type != "sand-yak":
        if enemy.health <= hero.health:
            if hero.isReady("jump"):
                hero.jumpTo(enemy)
            elif hero.isReady("cleave"):
                hero.cleave(enemy)
            elif hero.isReady("bash"):
                hero.bash(enemy)
            elif hero.isReady("punch"):
                hero.punch(enemy)
            else:
                hero.attack(enemy)
    elif enemy and hero.health <= enemy.health:
        hero.say("Help!")
        if hero.distanceTo(enemy) <= 10:
            hero.attack(enemy)
        else:
            hero.moveXY(42, 66)
            hero.shield()
    else:
        hero.moveXY(42, 66)

But it won’t detect the enemy health anymore :confused:

Ive been stuck on this level for almost a month now and i really need some hints on how to best do this

while True:
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type != "sand-yak":
        if hero.canCast("chain-lightning"):
            hero.moveXY(49, 42)
            hero.moveXY(81, 51)
            hero.cast("chain-lightning", enemy)
        elif hero.isReady("cleave"):
            hero.cleave(enemy)
        elif hero.isReady("bash"):
            hero.bash(enemy)
        else:
            hero.attack(enemy)
    else:
        enemy = hero.findNearestEnemy()

Equipment Code combat 4.3.21.PNG

Maybe for the cleave thing, you might want jump to the enemy then cleave.

Like this?

while True:
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type != "sand-yak":
        if hero.canCast("chain-lightning"):
            hero.moveXY(49, 42)
            hero.moveXY(81, 51)
            hero.cast("chain-lightning", enemy)
        elif hero.isReady("cleave") and hero.isReady("jump"):
            hero.jumpTo(enemy)
            hero.cleave(enemy)
        elif hero.isReady("bash"):
            hero.bash(enemy)
        else:
            hero.attack(enemy)
    else:
        enemy = hero.findNearestEnemy()

Try removing this, you don’t need to define enemy twice.

I did that because for some reason it won’t find the new nearest enemy when i kill the first one

I deleted some code and fiddled with it and it mangaed to work.
I think i over complicated it : /

Congrats man :partying_face: :partying_face: :partying_face:!!!

1 Like