Stumped on Thornbush Farm

I don’t know, it worked for me… I completed it, which gives me the ability to play more levels so I’m not complaining ; ).

That’s Not Working For Me

This is not working for me

in JavaScript

loop {
    this.moveXY(43, 50);
    var topEnemy = this.findNearestEnemy();
    if (topEnemy) {
        this.buildXY('fire-trap', 43, 50);
    }

    this.moveXY(25, 34);
    var leftEnemy = this.findNearestEnemy();
    this.buildXY('fire-trap', 25, 34);
    
    this.moveXY(43, 19);
    var bottomEnemy = this.findNearestEnemy();
    if (bottomEnemy) {
        this.buildXY('fire-trap', 43, 19);
    } 
}

Folks,

I am killing all three ogres. After killing all three ogres my knight moves north and reports seeing no one. He then builds another firetrap on the west side which kills the fourth ogre and then the knight moves south and builds another fire trap which kills the peasant

here is my code

// Patrol the village entrances.
// Build a "fire-trap" when you see an ogre.
// Don't blow up any peasants!

loop {
    this.moveXY(43, 50);
    var topEnemy = this.findNearestEnemy();
    if (topEnemy) {
        this.buildXY('fire-trap', 43, 50);
    }
    this.moveXY(25, 34);
    var leftEnemy = this.findNearestEnemy();
    if (leftEnemy)  {
        this.buildXY("fire-trap", 26, 34);
    }
    var bottomEnemy = this.findNearestEnemy();
    if (bottomEnemy)  {
        this.buildXY("fire-trap", 43, 20);
    }
    
    
    
}

Thank you for your help

Looks like you don’t moveXY to the bottom X before checking to see if there is an enemy, so you see the left enemy again and then build a trap for it at the bottom X.

@Asith please do not give out code and Please PLease read the FAQ on how to format your code properly

Hi bro !
For the last peasant he tell me that he didn’t see anyone but he put a fire-trap and he kill my peasant. I don’t enderstand why. Sorry if you answare to my question before, this is not my mother tongue ^^ (I think you see that ^^). I join you a screen shot of what’s happen :

I try to put in not on the X but it doesn’t work…
Thanks for your help !

@kalldrogo Did you change boots or get Ring of Speed recently ? If you run too fast, sometimes your hero will run faster than the level is expecting him to do so. The result is Ogres and Peasants will appear AFTER your code is checking for them, and won’t make a proper decition to lay a fire-trap down or not.

your “leftEnemy” if is “if topEnemy”…

move, set topEnemy, if topEnemy
move, set leftEnemy, if topEnemy . . . . . . . OOPS
move, set bottomEnemy, if bottomEnemy

2 Likes

First, thanks because you react fast !
Secondly, Thanks for the solution, I realy need to be more attentive of my syntax ! :grimacing:
It’s deficult to see our own errors ! :sweat:
Have a nice code !

the code that you put did not work for me!,