Clash of Clones Help!

Yes, you have to defeat the Clone and his army. Send your program and equipment and we are glad to help!

this is my code,
P.S fix this,

You’ll need good strategy to win this one!

in too this,

You’ll need a good strategy to win this one!

# You'll need a good strategy to win this one!
# Your clone will have the same equipment you have!
# But, they're not very skilled at using special powers.
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)
            if self.health < self.maxHealth:
                hero.shield()
                

and here is my equipment,


plese help if you can!

I don’t think you have the ability to do both of those…
Lydia

@Wincon did you copy your code from someone else? Because self have not been used since around 2017.

Andrei

2 Likes

my brother told me he is 3 years older than me.

but am still trying to learn more about codecombat!

Also, this is my code now ,

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("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)
            if self.health < self.maxHealth :
                hero.shield()

@Wincon Please don’t copy your brother’s code even though he let you use it, I suggest you try to write the code yourself first. Since you won’t learn anything if you don’t write the code yourself.

"Give a man a fish and he will eat for a day. Teach a man how to fish and you feed him for a lifetime." - Lao Tzo

1 Like

I was going to buy the emperor’s gloves but at that time I did not have many gems, so I bought steel striker now I have only 245 gems.

not that I copied the code, I learn “self” form my brother.

In that case, I’ll take a look in the code.

I don’t think there is anything wrong with my code. I think at least.

now this is my new code,

# You'll need a good strategy to win this one!
# Your clone will have the same equipment you have!
# But, they're not very skilled at using special powers.
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)
                else:
                    self.attack(enemy)
            else:
                self.attack(enemy)
            if self.health < self.maxHealth:
                hero.shield()

I wouldn’t recommend attack the enemies in the order of the array enemies. It doesn’t start with the nearest, so you’ll be running around the map. Try using nearest instead.

1 Like

this still doesn’t work,

#You'll need a good strategy to win this one!
# Your clone will have the same equipment you have!
# But, they're not very skilled at using special powers.
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)
                else:
                    self.attack(enemy)
            else:
                self.attack(enemy)
            if self.health < self.maxHealth:
                hero.shield()


Try to create yourself a code and we will gladly help you more @Wincon. If you just copy code, you will not learn anything and it will ruin this whole game’s teaching purposes.

Andrei

Ok, I will try that. (20 characters)

You do not need to check if your hero can build, but you’ll need the trap belt for this, do you have that?

If your hero’s health is below your hero’s maxHealth, your hero will keep shielding and will not attack. Maybe do something like:

if self.health < self.maxHealth / 5.

If needs to be in front of else, or the bottom if won’t run at all.
Lydia

1 Like

ok so I do have the trap belt, thanks.

Try fixing what I told you to fix, I extremely recommend flags in Clash of Clones, they help a LOT!
Lydia