Clash of Clones help

My hero dosent attck he just stands there

while True:
    enemies = hero.findEnemies()
    if enemies:
        if hero.isReady("cleave"):
            hero.cleave(enemies)
        else:
            hero.attack(enemies)
            hero.bash(enemies)
            hero.shield(3)

and it also dosent show the area or charecters.

Try to find the nearest one or specified enemy from all of them maybe.


def findStrongestEnemy(enemies):
    strongest = None
    strongestHealth = 0
    enemyIndex = 0
    enemy = hero.findNearestEnemy()
    # While enemyIndex is less than the length of enemies:
    while enemyIndex < len(enemies):
        # Set an enemy variable to enemies[enemyIndex]
        enemy = enemies[enemyIndex]
        # If enemy.health is greater than strongestHealth
        if enemy.health > strongestHealth:
            # Set `strongest` to enemy
            # Set strongestHealth to enemy.health
            strongest = enemy
            strongestHealth = enemy.health
        # Increment enemyIndex
        enemyIndex += 1
    return strongest
enemies = hero.findEnemies()
leader = findStrongestEnemy(enemies)
if leader:
        hero.attack(leader)
        if hero.isReady("cleave"):
            hero.cleave(leader)
        else:
            hero.attack(leader)
            hero.bash(leader)
            hero.shield(2)

if hero.health < leader.health:
    hero.shield(3)
    hero.moveXY(42, 38)
    hero.moveXY(39, 85)

I changed it but now when he moves he just stays there

You haven’t got a while loop for the lower section of your code, it will only happen once. You have to add some kind of loop.
Danny

Thank you so much

1 Like

def findStrongestEnemy(enemies):
    strongest = None
    strongestHealth = 0
    enemyIndex = 0
    enemy = hero.findNearestEnemy()
    # While enemyIndex is less than the length of enemies:
    while enemyIndex < len(enemies):
        # Set an enemy variable to enemies[enemyIndex]
        enemy = enemies[enemyIndex]
        # If enemy.health is greater than strongestHealth
        if enemy.health > strongestHealth:
            # Set `strongest` to enemy
            # Set strongestHealth to enemy.health
            strongest = enemy
            strongestHealth = enemy.health
        # Increment enemyIndex
        enemyIndex += 1
    return strongest
while True:
    
    enemies = hero.findEnemies()
    leader = findStrongestEnemy(enemies)
    if leader:
        hero.attack(leader)
        if hero.isReady("cleave"):
            hero.cleave(leader)
            hero.attack(leader)
            hero.attack(leader)
        else:
            hero.attack(leader)
            hero.attack(leader)
            hero.bash(leader)
            hero.shield(10)
    if hero.health < leader.health:
        hero.shield(3)
        hero.moveXY(42, 38)
        hero.shield(4)
        if leader < 10:
            hero.bash(leader)
            hero.attack(leader)
            hero.attack(leader)
            hero.cleave(leader)
        hero.moveXY(39, 85)
        hero.shield(5)
        

my hero dies at 0:28:1 and I only have 72 gems

I’m afraid from here it’s just about tactics… If you can’t get any more equipment.
Do you have the jump boots? Maybe try and make your way to the archers at the start and cleave them, that gives you a massive advantage over your clone, then attack your clone.
Also equip a bad sword and just kill the clone with bash and cleave and your soldiers, who you’ll have more of if you unbalance the numbers by killing their archers at the start.
I hope this helps
Danny

@Deadpool198 I don’t think jumping will help much because as far as I remember hero freezes for a while right after jump.

@Everncast There is nice tactic from @xython here Clash Of Clones Help appreciated
Maybe this will help you. Good luck!

I used it and it worked quite well. That happens if you target a location out of range of the shoes.
I do:

hero.jumpTo(Vector(exampleX, exampleY))
# then
hero.moveXY(exampleX, exampleY) 
# in case I didn't get there in the first place.

Oh, didn’t think about that. Thanks)

to Alex and Deadpool: “if you target a location out of range of the shoes” - never noticed such freeze.
I usually combine jump with move ( measured jump distance about 25 metres )

def heroMove(pos, distance = 20):
    if hero.isReady("jump") and hero.distanceTo(pos) > distance:
        hero.jumpTo(pos)
    else:
        hero.move(pos)
while True:
    # calling heroMove(pos) with default parameter
    heroMove(Vector(120,70)) # or
    # heroMove({'x':120,'y':70}, 25) # with parameter
2 Likes

thank you all so much for helping it works now