Google Blockly Maze Solved!!

Yesterday Google published an amazing tool google-blockly which is more or less similar to MIT Scratch. Blockly is a web-based, graphical programming language. Users can drag blocks together to build an application. No typing required :) All the code of Blockly is open source.

One of the demo programs involves solving a maze puzzle.

I had some good time playing around with the blocks and building up the logic that solves the puzzle. Here’s the solution that I came up with:

google-blocky-maze-solve

If you haven’t tried yet then do try it. Its real fun. Play Blockly-maze now.

Let me know if you have better/generic solution..

Update: I found below simpler and smaller solution on Internet. This solution not just solve the current Maze problem, but can any 2-dimensional maze problem.

google-blockly-maze-solution2
Get our Articles via Email. Enter your email address.

You may also like...

13 Comments

  1. Nuno Cancelo says:

    Hi,
    another solution is (and faster):
    repeat foreaver
    do move forward
    if not wall to the right
    then turn right
    else if not wall to the left
    then turn left

    • Thanks for posting. Your solution is indeed fast. But it works only with this maze setup. If I change the start/end position then it wont work. The second solution that I posted works in any scenario.

      • Carl Lajeunesse says:

        I doubt it. If a maze is a big (squared) circle with a path leading to the center (exit point) I think both “program” could loop the circle

        • Meh says:

          Nope, will solve any puzzle, see, it doesn’t do anything complicated, the second solution just follows a wall the whole time, so any path that is possible to get to in the third dimension will be traced by that program.

          • Meh says:

            *second dimension :P

  2. workmi says:

    Maze.turnLeft();
    while (true) {
      if (!Maze.isWallRight()) {
        Maze.turnRight();
        Maze.moveForward();
      }
      if (!Maze.isWallLeft()) {
        Maze.turnLeft();
        Maze.moveForward();
      }
      Maze.moveForward();
      Maze.checkTimeout();
    }
    

    • Nick says:

      This one also works.

      while (true) {
        if (!Maze.isWallRight()) {
          Maze.turnRight();
        }
        if (!Maze.isWallLeft()) {
          Maze.turnLeft();
        }
        Maze.moveForward();
        Maze.checkTimeout();
      }
      


      Cheers

  3. denious says:

    4 lines:

    repeat forever
    if (wall ahead or (not wall to the left or not wall to the right))
    turn randomly
    move forward

  4. paul says:

    Your solution doesn’t always work. It can get stuck in a loop in the upper right lane

  5. DWIPAYAN KAR says:

    plzzz…can anyone help me with installing BLOCKLY…cant figure it out at all…and i am sure a lot of novice like me is in a fix…..plz help us out….:)

  6. eric says:

    i like to use the if – else if – else to its fullest … and only use statements once …

    while (true) {
      if (!Maze.isWallLeft()) {
        Maze.turnLeft("44");
      } else if (Maze.isWallForward()) {
        Maze.turnRight("61");
      } else {
      }
      Maze.moveForward("1");
      Maze.checkTimeout("8");
    }
    


    reverse if you wish it to follow the right wall instead of the left …

  7. Kim Hao says:

    while (!false) {
      if (Maze.isPathForward()) {
        Maze.moveForward();
        continue;
      }
      if (Maze.isPathRight()) {
        Maze.turnRight();
        continue;
      }
      if (Maze.isPathLeft()) {
        Maze.turnLeft();
        continue;
      }
      if (Maze.isPathBackward()) {
        Maze.turnLeft();
        Maze.turnLeft();
      }
    }
    

  8. xc says:

    This is great but the on-line feature doesn’t have blocks that can be amended to that option, and the code itself can’t be modified.

Leave a Reply

Your email address will not be published. Required fields are marked *