Level : Black Diamond

First time I tried to access to this level, I got an infinite loop.
The code example has nothing to prevent it.

Hmm, which language? The current sample code shouldn’t include any infinite loops in any languages that I can see, but I might be missing something. (Also, is there a JS error in the console saying how it’s actually some other error, or is it actually an infinite loop?)

It’s in JS.
I was using the link in the mail. I must use the possibility to comment the code to get access to the level. I got the error (infinite loop with a popup, I did not check the console) during the loading.

Here’s the default code :

loop {
    var gem = this.findNearest(this.findItems());
    if (gem) {
        var clear = this.isPathClear(this.pos, gem.pos);
        // The isPathClear method tells you if there’s an obstacle in the way.
        // If it’s clear, move() to gem.pos.
        // Else, move back to the center point.

As it does no action, I supposed it loops very fast and endlessly.

I just try to reset the code, and the error did not appear anymore. Anya just do nothing.

I do not have time. Although there is no mention of the limitation.
I do popodalis into any trap and find all diamonds. But I can not win because time is over :frowning:

Here is my code:

angle = Math.PI / 2 - Math.PI / 16
center = {"x":40,"y":35}
def movePos(angle):
                targetX = self.pos.x + 3 * Math.cos(angle)
                targetY = self.pos.y + 3 * Math.sin(angle)
                return  {"x":targetX,"y":targetY}
    gem = self.findNearest(self.findItems())
    if gem:
        clear = self.isPathClear(self.pos, gem.pos)
        if clear:
        elif self.isPathClear(self.pos, center):
            new_pos = movePos(angle)
            while self.isPathClear(self.pos, new_pos) != True:
                angle -= Math.PI / 16
                new_pos = movePos(angle)

Ah, very clever! I’ve increased the lifespan of the level by 5s, so you should be able to finish it now.


Sweet code reuse. 

Nice! really smart! never thought about something like that! (This kinda lame, but the only way I could think of finishing it witout using the original code was to just get the X and Y positions and use the ‘moveXY’ function :sweat:)

self.isPathClear does not seem to register the traps in Python, even though it says it should. It is making this level very difficult without manually choosing my locations.

Hmm, is working for me…

Did you rewrite the code? or just add the two lines it wants you to add?
(this is one of the “don’t think to hard or you’ll break it” levels.)

It works now, but the pathing is quite weak. It will say the path is clear but I will often clip the corner of the trap. But I have finished the level at least.

Make sure you use Compound Boots and the move function (not moveXY) on this level. As the comments in the code suggest, should only be a few lines of code.



I did some modifications on your code.

It’s in the javascript syntax now.

For those who might need it.

(Solution removed)

Please don’t post solutions. The purpose of this board is to help people learn so that they can figure out levels on their own. Simply providing solutions does not help and is counterproductive. Thanks.