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



12 Comments

  • Nuno Cancelo 15 June, 2012, 21:28

    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

    • Viral Patel 15 June, 2012, 21:43

      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 16 June, 2012, 1:13

        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 31 August, 2013, 1:29

          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 31 August, 2013, 1:30

            *second dimension :P

  • workmi 17 June, 2012, 15:03
    Maze.turnLeft();
    while (true) {
      if (!Maze.isWallRight()) {
        Maze.turnRight();
        Maze.moveForward();
      }
      if (!Maze.isWallLeft()) {
        Maze.turnLeft();
        Maze.moveForward();
      }
      Maze.moveForward();
      Maze.checkTimeout();
    }
    
    • Nick 17 June, 2012, 22:31

      This one also works.

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

      Cheers

  • denious 26 June, 2012, 0:13

    4 lines:

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

  • paul 8 November, 2012, 4:05

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

  • DWIPAYAN KAR 8 December, 2012, 20:50

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

  • eric 12 December, 2012, 1:28

    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 …

  • Kim Hao 20 March, 2013, 17:13
    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();
      }
    }
    

Leave a Reply

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

Note

To post source code in comment, use [code language] [/code] tag, for example:

  • [code java] Java source code here [/code]
  • [code html] HTML here [/code]

Current ye@r *