Clash of Clones - Is it possible to win?


#1

I gave up on the warrior, as the other warrior just ties me and he has a bigger army. I have been trying it with the archer. No matter what I do, I can never win. And half the time a yak walks in front of my arrows and then kills me, but even when that doesn’t happen I still lose. Here is my code, is runs fine but isn’t good enough. Anyone have some suggestions?

loop:
    enemies = self.findEnemies()
    enemyIndex = 0
    # Make an array of all enemies.
    while enemyIndex < len(enemies):
        currentTarget = enemies[enemyIndex]
        enemyIndex += 1
        distance = self.distanceTo(currentTarget)
        # If it's a sand-yak, move to next enemy in the array.
        if currentTarget.type is "sand-yak":
            pass
        # If it's out of range, move to the next enemy in the array.
        elif distance > 37:
            pass
        # Else, we target it.
        elif currentTarget.health > 0:
        # If it's too close, move back.
            if distance < 18:
                self.moveXY(self.pos.x - 15, self.pos.y)
        # Else, we attack it.
            else:
                self.attack(currentTarget)


#2

Its hard, but beatable. Remember that the toughest enemy will be the clone, which is identical to your hero except that it is only programmed to attack the nearest target with whatever your primary weapon is. So I suggest not equipping powerful weapons or armor, since that only makes the clone stronger. Instead rely on secondary weapons and effects, like spells if your playing a mage, or throwing knives/bombs as an archer. You don’t even need to equip a primary weapon, in which case the clone won’t even attack.

Also don’t forget that you have allies, try to keep them alive if you can. I also suggest that you prioritize ranged targets above melee ones, especially shamans, you want to kill those quick.

Another alternative is to go with a powerful weapon on the archer, but light on armor, and take the clone out first. It’s starting health will be equal to yours, so if you start low you can often kill him while he’s still targeting your allies.


Clash of Clones Help!
Game Pacing, Gem Deprivation and Difficulty spike
#3

How do I target the clone? I can’t find his enemy.type
Also, thanks for the advice!


#4

The clone’s type will be the same as your heroes, so do self.say(self.type) to find out what that is.

Oh, and did you know there’s a simpler way to loop through an array in Python?

loop:
    enemies = self.findEnemies()

    for currentTarget in enemies:
        if currentTarget.type != "sand-yak":
            #do stuff

Don’t have to worry about indexes this way.


Dunes help. Not sure on how to void an enemy
#5

Wow, thank you! I have so many questions and that helps with a few. I don’t understand the self.say(self,type)? What do you mean?


#6

It’ll cause your hero to say his type in a text bubble. Since the clone has that same type, you will then know what the clone’s type is.

But now that I think if it, I made a list of them a while back, so here it is:
Anya - captain
Tharin - knight
Hushbaum - librarian
Amara - ninja
Omarn - potion-master
Hattori - samurai
Senick - trapper
Naria - forest-archer

Whichever hero you are playing, find its type on this list. The clone will be using that same type. You can then target the clone.


#7

Thank you! I somehow beat it, barely. I can’t get the thing you taught me to work
for ____ in _____'s:
if _______

Can you clarify what you meant? I can seem to set ‘gem’ to anything that it will register.

loop:
    gems = self.findItems()
    gem = self.findNearest(gems)
    for gem in gems:
        if self.distanceTo(gem) < 10:
            self.move(gem.pos)

#8

‘for gem in gems:’ will loop through the ‘gems’ array and set ‘gem’ equal to the current element in the array at each iteration.

It’s equivalent to:

gemsIndex = 0
while gemsIndex < len(gems):
    gem = gems[gemIndex]
    gemIndex += 1

Just a bit simpler.

I’m not sure what you are trying to accomplish with the code you posted. If you want to move to the closest item with a distance < 10, you dont need a for loop for that. The following would work just fine.

loop:
    gems = self.findItems()
    gem = self.findNearest(gems)
    if self.distanceTo(gem) < 10:
        self.move(gem.pos)

Here is an example of when you might use a for loop, finding the nearest enemy that is not a sand yak:

loop:
    enemies = self.findEnemies()

    nearestEnemy = None
    for enemy in enemies:
        if enemy.type != "sand-yak":
            if not nearestEnemy:
                nearestEnemy = enemy
            elif self.distanceTo(enemy) < self.distanceTo(nearestEnemy):
                nearestEnemy = enemy
                
    if nearestEnemy:
        self.attack(nearestEnemy)

If it still isn’t making sense, have a look at the documentation:
https://wiki.python.org/moin/ForLoop


#9

Small hint (you can use it somewhere else as well, just think creative):

If you ever looked in the level-editor, there is always a blanko-hero that is named Hero Placeholder. If there is a second one, it is (usually) named Hero Placeholder 1 (beware the space!). You can then filter by ID.

myHero    = [e for e in self.getFriends() if e.id == 'Hero Placeholder'][0]
enemyHero = [e for e in self.getEnemies() if e.id == 'Hero Placeholder 1'][0]

This is the quick and (really) dirty way to get the hero-object(s). Notice that [e for e in LIST if CONDITION] is a list-assembly function, therefor the result is also a list. I then access the first index ([0]), blindly relying there is one entry. Usually you want to check this first! (Use len(LIST) to get the length).

A more in-depth manual can be found here. This piece of candy offered by the python developers is something you soon will not miss in any program you write.


#10

I won with Anya.


#11

Cool, thanks Glacian! But don’t make it too easy for us… :smile:


#12

I’m trying Naria w/o a primary weapon and it won’t even run. I’m wondering if lack of a primary weapon is causing a problem for the clone Naria? Here’s a really simple version of my code that won’t even run.

loop:
    enemy = self.findNearest(self.findEnemies())
    if enemy:
        if self.isReady("throw"):
            self.throw(enemy)


#13

@nick I think there’s a bug with clone-ranger code? (accidental pun, haha) The code in the preceding will not work with Naria or Sennick but essentially the same code (merely replacing throw with bash) will work fine for Tharin.


#14

At risk of taking this too far, you can also add enumerate:

for index, currentTarget in enumerate(enemies):

where index will go 0, 1, 2, . . . Very handy on some occasions (e.g. Slalom level on mountain)


#15

We’ve just made it easier so that it should be more doable just by being smart about targeting archers, not needing nerfing your own weapon to do.

@eiler13 I found the bug with the razor disc that was trying to use the attack instead of the throw when it hit something, so it should be good to go now; thanks for the bug report!


#16

I (Anya) didn’t need to lose her weapon, but she did need to run away a little so her clone would loose enough health so she could win (kite around her archers kind of thing). I never tried the no primary weapon thing, cool idea, I guess that is what I get for assuming her clone new about all the attack forms. (a big if/elif isReady ) it was also touch and go depending on when/if the first shaman/(bigger)ogres came out. Sounds like it is time to go play it again.


#17

@juraj_pechac

Thanks for the code! I changed it up a bit and it worked for me!

you have got to be kidding me? I beat it like this??? It was so funny! :scream: :joy: :stuck_out_tongue_closed_eyes:
this was my code:

Mod edit: Please do not post solutions. Thanks.

just don’t forget to indent it your self if you use it!
P.S I you haven’t tried it out yet (which I recommend you do even if you finished it already) it’s funny because since there is no weapon in the weapon spot, the CPU clone of you will not move, shield, or even bash! (cause thats what i used as an attack) LOL :laughing:


#18

I am especially happy because that was the best stuff for that class, and right now i have negative gems


#19

I would kinda like to see levels where if its to hard you can just change your armor it would to use elements out off the code and get a little clever with your equips


#20

Hi :
I shared my code by combining other people ways before.
I did not equip the primary weapon.
this is my role:

The tip:
I moved my role forward then back quickly to attract the fire from archers.
then stop to watch the battle ending

Mod edit: Please do not post solutions. Thanks.

This is a cool game.I love it!