The Final Kithmaze


#1

I’m trying to make a loop to get all the way through the maze. Help?


#2

What have you tried so far?


#3

I tried this:
this.moveRight();
this.moveUp();
this.attack(“Blorp”);
this.attack(“Blorp”);
this.moveRight();
this.moveDown();
this.moveDown();
this.moveUp();
this.moveRight();
this.moveUp();
this.attack(“Bop”);
this.attack(“Bop”);
this.moveRight();
this.moveDown();
this.moveDown();
since the loop wouldn’t work, but i didnt realize how long the maze was, so it would take more lines of code than a loop would.


#4

You’ll need to use a variable to attack the nearest enemy at each step of the maze where you run into line of sight of an ogre. That’s how you can use a loop to do it. You don’t need to know an enemy’s name to attack it when you use a variable, so each iteration of the loop can be the same.

var enemy = this.getNearestEnemy();
this.attack(enemy);

#5

I tried the code given:

var enemy = this.getNearestEnemy();
this.attack(enemy);

However, it does not work! Going the long way is the only way for me to beat the level.


#6

@Tamer The code should work if it’s inside a loop with the right movement commands (and two attack commands per loop, since enemies take two hits). What kind of problems did you see that made it not work?


#7

I am seeing this issue in Clojure too, when adding the following code inside a loop:

(let [enemy (.findNearestEnemy this)]
         (.attack this enemy)
         (.attack this enemy)
)

It only executes the move sentences and ignores the attack ones.


#8

@Crackers Do you find the enemy when you are in visual range of it, or is it behind a wall? It will store a nil value in the enemy variable if findNearestEnemy has line of sight blocked when you call it.


#9

It is inside my visual range, the code did work on other languages though.

I saw this happening on other levels, for example on the one you have to plant bombs and patrol an area, only on clojure I had a problem where the character would only move and never plant the bombs.


#10

It happened to me too, i had to write (.attack this (.findNearestEnemy this)) every time, but to be honest it seems like a bug to me


#11

I’ve opened a bug issue here to track this one: https://github.com/codecombat/aether/issues/124


#12

Same here. The let statements are ignored inside a dotimes.