Siege of Stonehold, please help me with it


#1

I need help on Siege of Stonehold, please help.
here is my code by the way, it’s in Python

loop:
    flag = self.findFlag()
    if flag:
      this.pickUpFlag(flag)
        
    else 
        enemy = self.findNearest(enemy)
    
    if enemy:
        elif self.isReady("cleave")
            self.cleave(enemy)
           
    else 
        self.attack(enemy)
        self.attack(enemy)

thanks if you help me with this and i’m sorry if you have to translate this into JavaScript or whatever


#2

Hello there !

Siege of StoneHold is the first complex level you face ! It’s normal to find it hard. Don’t panic ! It’s ok to be defeated several times before you can find a way to victory !

First of all, I think you changed recently your glasses, because you’re not using them right. Your line :

enemy = self.findNearest(enemy)

is wrong. The "findNearest(units) is expecting an array of units. You can find this array of the enemies by changing this line by these two :

enemies= self.findEnemies()
enemy = self.findNearest(enemies)

What I did the first time I beat this level is to understand one thing :

Your archers are the key ! Protecting them is far better than killing enemies !

There are many ways to protect them. You’ll see the bunch of the soldiers is protecting the north. Try to protect them from the south. Stay close to them and try to take as little damage as possible. Don’t fight if your archers arn’t close to you. Also, try to heal from time to time by going back to the base.

I tried the following code, and I won ! This code is in JavaScript, sorry I never learnt Python and came accross some weird indent bugs when trying to provide a python one. I took your code and added a distance condition, to only attack nearby enemies because I don’t care about northern enemies. All my men died, but I lived and killed the last ogre myself. Took me 3 attempts. Good luck ! Try to code it in Python now !

Oh ! And there are MANY better ways to protect your archers. If you’d like to hear about it, come back in this thread.

loop{
    flag = this.findFlag();
    if (flag){
        this.pickUpFlag(flag);
    }else{
        enemies= this.findEnemies();
        enemy = this.findNearest(enemies);
        
        if (enemy&&this.distanceTo(enemy)<40){
            if(this.isReady("cleave")){
                this.cleave(enemy);
            }
            else{ 
                this.attack(enemy);
                this.attack(enemy);
            }
        }
    }
}

Here is my stuff :