Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Clash of clones need help


#1

please help if you know how to do this level

enemy=hero.findNearestEnemy()
if hero.distanceTo(enemy) == 4:
    if self.isReady("cleave"):
        self.cleave(enemy)
    else:
        self.attack(enemy)


#2

Have you tried using flags? It’s also about strategy, not just the code.


#3

okay i’ll try that. :grinning:


#4

for some reason my hero will not move??

flag=hero.findFlag("green")
if flag:
    hero.pickUpFlag()
    enemy=hero.findNearestEnemy()
    if enemy:
        if self.isReady("power-up"):
            self.powerUp()
        else:
            self.attack(enemy)


#5

oh wait i was using progamation I


#6

now my hero just keeps on diying ???


#7

Put that code into a while True loop to make it check every frame


#8

Okay i tried that but now my hero keeps on dying.???


#9

Ok, it depends on your strategy. This level has many many solutions, so it depends on your strategy whether you manage to win or not.


#10

then what strategy should i use depending on my gear


#11

Read this post and develop a strategy. Start writing your code. If the code fails, post it here and we’ll help you with it. No one is going to tell you how to develop a strategy. That’s up to you.

Be sure to read all you can about this level for some hints on how you want your strategy to work.

https://discourse.codecombat.com/search?q=clash%20of%20clon


#12

thanks MunkeyShynes but here’s my code

while True:
    flag=hero.findFlag("green")
    if flag:
        hero.moveXY(flag.pos.x, flag.pos.y)
        enemy=hero.findNearestEnemy()
        if enemy:
            if hero.isReady("bash"):
                hero.bash(enemy)
            if hero.isReady("power-up"):
                hero.powerUp()
            else:
                hero.attack(enemy)
        hero.findNearestEnemy()
        if enemy.type=="yak":
            hero.say("leave me alone")



#13

You don’t have any code to pick up the flag. Click on the methods in the middle of the game screen to see how to properly use them. Also, always remember that any time you use hero.say, this takes a whole second of time. Often this time can be costly if you’re being attacked. Also, just a suggestion but try if enemy.type != "yak": for attacking enemies. That way, you won’t attack yaks.