What are you supposed to do in the siege of stonehold?

So this is my progression so far:

loop:
    enemy = self.findNearestEnemy()
    distance = self.distanceTo(enemy)
    flag = self.findFlag()
    if distance < 20:
        if self.isReady("cleave")
            self.cleave(enemy)
        if not self.isReady("cleave") and self.isReady("bash")
            self.bash(enemy)
        else:
            self.attack(enemy)
            self.attack(enemy)
    if not distance < 20:
        flagpos = flag.pos
        fx = flagpos.x
        fy = flagpos.y
        self.moveXY(fx, fy)
        self.pickUpFlag(flag)

I still cant get it with about 370 health and cleaving.
HELP!

2 Likes

Check the sticky post at the top of this forum for how to format the code.

You would also have to place the flags really, really cleverly (like I do) to be able to do it with that little health. It took me four tries, and I helped build the level, so I know all the tricks about how to ambush the enemies.

2 Likes

Thanks a lot! I’ll try

2 Likes

Here is my code. Just make sure you indented it right. I used Tharin who I have pretty good armor and sword. Hope this help.

loop:
enemy= self.findNearestEnemy()
flag = self.findFlag()
if flag:
self.pickUpFlag(flag)
if enemy:
self.attack(enemy)

2 Likes
loop:
    enemy = self.findNearestEnemy()
    distance = self.distanceTo(enemy)
    flag = self.findFlag()
    if distance < 20:
        if self.isReady("cleave"):
            self.cleave(enemy)
        if not self.isReady("cleave") and self.isReady("bash"):
            self.bash(enemy)
    else:
            self.attack(enemy)
            self.attack(enemy)
    if not distance < 20:
        flagpos = flag.pos
        fx = flagpos.x
        fy = flagpos.y
        self.moveXY(fx, fy)
        self.pickUpFlag(flag)

this is my code like the one from meritrapa but still my flags don’t seem to work but i can’t figure out why

2 Likes

I added code tags for you so I could read your code.

If the indentation is correct, you are attacking the enemy if it is more than 20 away from you, then you are looking for the flag. I think you want that else tabbed in.

Also, your if not statements should just be elif statements:

loop:
    enemy = self.findNearestEnemy()
    distance = self.distanceTo(enemy)
    flag = self.findFlag()
    if distance < 20:
        if self.isReady("cleave"):
            self.cleave(enemy)
        elif self.isReady("bash"):
            self.bash(enemy)
        else:
            self.attack(enemy)
    else:
        flagpos = flag.pos
        fx = flagpos.x
        fy = flagpos.y
        self.moveXY(fx, fy)
        self.pickUpFlag(flag)

You also don’t need to attack twice because you are in a loop and thus you automatically attack repeatedly.

2 Likes

And you’re not checking for if a flag has been placed with an if flag: check.

2 Likes

thnx a lot guys but why does it still keep telling me to find the distance to a target unit

2 Likes

Because you don’t check if there is an enemy before checking for the distance. Similar to what you had to do in ā€œPatrol Busterā€

2 Likes

i found my problem lol, i have 376 health and no more gems to buy items
any tips on where to get gems?

2 Likes

I have that same issue, I bought this 400 gem sword right before getting the longsword, and then I never used the sword that I bought. Is it possible to implement a selling feature?

2 Likes

you bought the katana? if so same exact thing happened to me

2 Likes

Yea. I was saving up, and saving up, and saving up, and bought it on the level right before the longsword. I used it once.

2 Likes

We’ll hope to implement selling soon, but it might take a while, as it’s kind of complicated. The katana can be more useful than the longsword in some levels where you don’t have to do AoE damage.

2 Likes

but in levels like stokehold its impossible to do it with 370 health and no gems, so patience is my victory?

2 Likes

Well, you could of course purchase gems… And possibly with the right style you could still beat it, would take some pretty good code I think though.

I actually haven’t beaten it with my warrior yet, only my ranger.

2 Likes
# You'll need great equipment and strategy to win. Here's what I pieced together.
# strategy 1 build fire-traps to continue to eliminate enemy
# strategy 2 use flags to maintain fire-traps and avoid enemies
    
self.buildXY("fire-trap", 10, 7)
self.buildXY("fire-trap", 11, 12)

self.buildXY("fire-trap", 54, 12)
self.buildXY("fire-trap", 52, 17)
self.buildXY("fire-trap", 61, 11)
self.buildXY("fire-trap", 58, 18)
self.buildXY("fire-trap", 62, 17)

self.buildXY("fire-trap", 112, 24)
self.buildXY("fire-trap", 112, 27)
self.buildXY("fire-trap", 112, 30)
self.buildXY("fire-trap", 112, 37)
self.buildXY("fire-trap", 112, 44)
self.buildXY("fire-trap", 112, 47)

self.buildXY("fire-trap", 126, 115)
self.buildXY("fire-trap", 126, 122)
self.buildXY("fire-trap", 117, 121)

self.buildXY("fire-trap", 80, 121)
self.buildXY("fire-trap", 74, 121)
self.buildXY("fire-trap", 68, 121)

self.buildXY("fire-trap", 29, 130)
self.buildXY("fire-trap", 27, 125)
self.buildXY("fire-trap", 21, 120)
self.buildXY("fire-trap", 17, 117)
self.buildXY("fire-trap", 11, 114)

self.buildXY("fire-trap", 26, 74)
self.buildXY("fire-trap", 26, 71)
self.buildXY("fire-trap", 26, 67)
self.buildXY("fire-trap", 26, 63)

loop:
    gFlag = self.findFlag("green")
    vFlag = self.findFlag("violet")
    bFlag = self.findFlag("black")
    enemy = self.findNearestEnemy()

    if gFlag:
        # What happens when I find a green flag?
        self.pickUpFlag(gFlag)
        pos = gFlag.pos
        x = pos.x
        y = pos.y
        self.buildXY("fence", x, y)
    if vFlag:
        # What happens when I find a violet flag?
        self.pickUpFlag(vFlag)
        pos = vFlag.pos
        x = pos.x
        y = pos.y
        self.buildXY("fire-trap", x, y)
    if bFlag:
        # What happens when I find a black flag?
        self.pickUpFlag(bFlag)
        pos = bFlag.pos
        x = pos.x
        y = pos.y
        self.moveXY( x, y)
                    
    elif enemy:
        if self.distanceTo(enemy) < 5:
            if self.isReady("bash"):
                self.bash(enemy)
            if not self.isReady("bash"):
                self.shield()
                self.shield()
                self.shield()
3 Likes

Through Hour of Code, the school got my son on and he has been playing all weekend, finally making it to this last level. He can’t find a way to earn any more gems at this point - there doesn’t seem to be anything repeatable and he has beaten all the ones that aren’t behind a pay wall up to the Siege.

He got the Mahogany Glasses and the Steel Striker and has been using the following to stay with army and help in as many ways as possible:

My son seems to be really close… He makes it to about 1:40. Any suggestions to seal the deal?

loop {
   var x = this.pos.x;
   var y = this.pos.y;
   var enemies = this.findEnemies();
   var friends = this.findFriends();
   
   var flag = this.findFlag();
   if (flag) {
       this.pickUpFlag(flag);
   }
   
   // If there are more than 3 enemies in range, cleave
    var enemiesInRange = 0;
    var closestEnemy = this.findNearest(enemies);
    if (closestEnemy && 
        this.distanceTo(closestEnemy) > 50) {
        closestEnemy = null;
    }
    
    if (this.isReady("cleave")) {
        this.shield();
        for (var i = 0; i < enemies.length; ++i) {
           enemy = enemies[i];
           if (this.distanceTo(enemy) < 10) {
               ++enemiesInRange;
               if (this.isReady("bash") && 
                   ("ogre" == enemy.type) ||
                   ("shaman" == enemy.target)) {
                    this.say("Bash the Ogre!");
                    this.bash(enemy);
               }
           }
       }
       if (closestEnemy)
       {
           if (enemiesInRange > 1) {
               this.say("Cleave!");
               this.cleave(closestEnemy);
           } 
       }
   }
   if (1 == enemiesInRange) {
       this.say("En Garde!");
       this.attack(closestEnemy);
   }
   
   var friend = this.findNearest(friends);
   if (!friend || "peasant" == friend.type) {
       friend = closestEnemy;
   }
   if (friend) {
       var diffX = friend.pos.x - this.pos.x;
       var diffY = friend.pos.y - this.pos.y;
       this.shield();
       while (Math.abs(diffX) > 10) { diffX /= 10; }
       while (Math.abs(diffY) > 10) { diffY /= 10; }
       this.moveXY(x + diffX, y + diffY);
   }
}
2 Likes

Hey, you don’t need all that code, just use

JavaScript:

loop {
    var enemy = this.findNearestEnemy();
    var flag = this.findFlag("green");
    if (flag) {
        this.pickUpFlag(flag);
    }
    else {
    if (enemy) {
        if (this.isReady("cleave")) {
            this.cleave(enemy);
        }
        else {
            this.attack(enemy);
}
}
}
}

(You need about 475-500+ health, and great sword or up)
Move your character with a green flag into the upper left hand corner, and then when the ogres come, he cleaves, and kills them. Then move your character into the upper right hand corner and he does the same thing. Then move him in with the villagers, and make him try to get a flag on the other side of the wall, so he will be stuck. Then once all your allies are dead, move the flag onto the field, and clear out the remaining enemies. Best of luck!

For Python users:

loop:
    enemy = self.findNearestEnemy()
    flag = self.findFlag("green")
    if flag:
        self.pickUpFlag(flag)
    elif enemy:
        if self.isReady("cleave"):
            self.cleave(enemy)
        else:
            self.attack(enemy)
2 Likes

Thanks man you really saved my ass back there, i got stuck and had a gems problem so because of you i got through the level with 370 health

2 Likes