Black Diamond Help


I was going back in the mountain levels and retried this one. For some reason I can’t go back to the middle without running into traps yet I followed the tips exactly.

while True:
    gem = hero.findNearest(hero.findItems())
    if gem:
        clear = hero.isPathClear(hero.pos, gem.pos)
        # The isPathClear method tells you if there’s an obstacle in the way.
        # If it’s clear, move() to gem.pos.
        if clear:
        # Else, move back to the center point.
            hero.moveXY(40, 35)

Please help.


You need to change the moveXY to move. Do this instead:



Yes @Chaboi_3000 is correct. Using MoveXY will just directly move to the destination. Using move will help you move step by step so its safer


I tried many times but failed until i saw this post:

It helped a lot.

And here’s the javascript version of 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.


I’m confused at how this works. If I use moveXY to get back to the center, my character just heads headlong into the traps. If I use move instead, he threads his way around the traps to get back - you can see the curvy path on the screen. Why is the isPathClear method required if ‘move’ steers around the traps?


Because moveXY and move methods work very differently. The main difference between moveXY and move methods is that when executing the moveXY method, the hero will not do anything else until this is completed. The code doesn’t move to the next line and no other line of code is considered until the hero arrives at the x,y coordinate of the cited position. With the move method, the hero takes a single step toward the target coordinates and then the code iterates through to see if there’s anything else it should, or could, be doing. In some situations, one is better to use than the other. In other situations, it doesn’t make any significant difference.