Level : Black Diamond


#1

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


#2

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?)


#4

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.


Black Diamond Help
#5

Hello.
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}
            
loop:
    gem = self.findNearest(self.findItems())
    if gem:
        clear = self.isPathClear(self.pos, gem.pos)
        if clear:
            self.move(gem.pos)
        elif self.isPathClear(self.pos, center):
            self.move(center)
        else:  
            new_pos = movePos(angle)
            while self.isPathClear(self.pos, new_pos) != True:
                angle -= Math.PI / 16
                new_pos = movePos(angle)
            self.move(new_pos)

#6

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


#7

Sweet code reuse. 


#8

@insaf121
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:)


#9

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.


#10

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.)


#11

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.


#12

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.


#13

@insaf121

Awesome!

I did some modifications on your code.

It’s in the javascript syntax now.

For those who might need it.

(Solution removed)


#14

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.