Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Clash Of Clones HELP PLEASE

def findWeakestEnemy():
    ememies = hero.findEnemies()
    weakest = None
    leastHealth = 99999
    enemyIndex = 0
    for enemy in hero.findEnemies():
        if enemy.health < leastHealth:
            weakest = enemy
            leastHealth = enemy.health
        return weakest

while True:
    weakestEnemy = findWeakestEnemy()
    if weakestEnemy:
        hero.attack(weakestEnemy)

Please help. My hero does not live long enough to kill the ogres. How do I finish the level?

In this case, the best you can do is get better armor. Your clones will have the same equipment you have, so you will need to “bulk up.”

There is nothing wrong with your code, however.

To add to what @TheBredMeister is saying…the enemy hero will exactly match you, as far as armor, weapons and health. But, where he cannot match you is with tactics, special moves, etc…he won’t cleave, can’t use the Emperor’s Gloves (for example), etc.

I’d recommend starting with the archers and take them out first (which you might be doing with weakestEnemy already). Also, keep an eye on your hero’s health…I coded mine to have him withdraw behind his troops, to give himself a breather and allow the Wooden Strand a chance to regenerate him some, before plowing in again.

@dedreous is correct in his summation, but you should also keep in mind using the Steel Ring to slow down your clone so he can do less damage to your soldiers.

Also, if you do have access to premium, use your pet to kill the archers while taking care of the frontline soldiers, then taking a breather

How do I use the steel ring?

Like how do I target my clone?

I passed the level by using the hero.cast(shockwave, enemy)

which item does that?

but my hero gets killed by the archers when she does that(like when she retreats)

Which hero are you using and what special gear (rings or emperor’s gloves) do you have? How many gems do you have? Using a hero that has special abilities helps to. The subscribers really benefit on this level with access to more gear.

To target your clone, you can check for the enemy.type using the list below since your enemy matches your type.

What items would you suggest I get?

These are a list of the items I think are the best, if you can afford them. They’re in priority order, depending on your specific tactic.

  1. Emperor’s gloves
  2. Cleave Sword (Long Sword)
  3. The jump boots can be helpful when used with the above 2 :arrow_double_up: to jump into the archers at the start
  4. A bash shield to attack their hero
  5. The Ring of earth is good.
  6. The Steel ring is ok if you use it on the clone, but any of the above are better :arrow_double_up:
  7. The Ring of invisibility is alright, and you’ll probably get it at some point down the line because it’s so useful.

I cannot guarantee any of these will actually make you win but they should help, if you write good code.
Danny

Ok so this is my new code. It keeps ignoring the retreat part this part ( if hero.health < 500: hero.moveXY(49, 65))

def findWeakestEnemy():
    ememies = hero.findEnemies()
    weakest = None
    leastHealth = 99999
    enemyIndex = 0
    for enemy in hero.findEnemies():
        if enemy.health < leastHealth:
            weakest = enemy
            leastHealth = enemy.health
        return weakest

while True:
    weakestEnemy = findWeakestEnemy()
    ememies = hero.findEnemies()
    enemy = hero.findNearestEnemy()
    hero.shield()
    if hero.health < 500:
        hero.moveXY(49, 65)
    if weakestEnemy:
        hero.attack(weakestEnemy)
    if hero.isReady("cleave"):
        hero.cleave(hero.findEnemies())
    else:
        hero.attack(enemy)
    if hero.canCast("chain-lightning", hero.findNearestEnemy()):
        hero.cast("chain-lightning", hero.findNearestEnemy())
    else:
        hero.attack(enemy)
    if hero.canElectrocute(hero.findNearestEnemy()):
        hero.electrocute(hero.findNearestEnemy())
    else:
        hero.attack(enemy)
    

the item I used was elemental vortex v

The one issue I see that will create prevent your hero from retreating is calling hero.attack(enemy) multiple times on the same enemy. If the enemy dies on the first attack, your hero will still try to attack the dead enemy. Since it is dead, it won’t continue the code and you can get stuck.

Consider using if - elif - else to run through the sequence of special attacks, if nothing else then attack. When you are using the special attacks, don’t look for a nearest enemy again, use the same one you declared at the top. Put the strongest attacks at the top of the list so they take priority when available. Another little thing, the shield works for less than a second, so unless you put it in a loop it doesn’t protect you much and takes away time from your attacks. If you regenerate health, maybe put a while loop with the shield after you checked your health and the hero moved to the safe location. This may buy you enough time to use the special attacks again after their cooldown period

One last detail, the function findWeakestEnemy() is not returning the weakest enemy. The return needs to be outside of the for loop (indentation inline with the “for”) to check every enemy. Now it is returning the first one on the list.

1 Like

You mean like this?

while True:
    if hero.health < 500:
        hero.shield()
        hero.moveXY(49, 66)
        hero.wait(5)

But I don’t know which attacks to put elif on…

I think what he means is to make one big if statement broken down into sub ifs, elifs and elses.
This is a basic enemy attack structure which I always use:

enemy = hero.findNearestEnemy()
if enemy:
    if hero.isReady("special-attack"):
        hero.specialAttack(enemy)
    elif hero.canCast("cool-spell"):
        hero.cast("cool-spell", enemy)
    else:
        hero.attack(enemy)

I think what brooksy (welcome back! :grin:) meant here:

Is that you checked your health at the start, like you have done. Then you move to your safe location, then you do something like:
while certainCondition == True, or while certainValue <= 10.
Then, you can shield while that condition you’ve chosen is true, or, if it’s a value, while it’s above a certain level. Then you can continue with the rest of your code.
To stop your hero from ignoring the retreat part of you code, as brooksy said, you need to implement elifs like in the basic attack structure above.

while True:
    if retreat == True:
        hero.retreat()
    elif somethingElse:  # all if statements from hereon downwards need to be elifs instead 
        # continue your code

The reason for the elifs is because otherwise your hero is confused about what to do:
“My health is less than 500, BUT there’s also a weak enemy. What should I do?!!??”
When you use elif it only does the elif code if the condition of the if statement above is not met.
I hope this helps
Danny

3 Likes

Actually nvm. I BEAT IT!!!

Way to go @SilverMe!
Everyone needs a little nudge now and then so don’t be afraid to ask for helo in the future!
Now go and dominate Cloudrip Mountain!

1 Like