blockly

Solve this Google Blockly maze


I'd appreciate some help finishing this blockly maze.

https://blockly-games.appspot.com/maze?lang=en&level=10&skin=0

enter image description here

This how far I was able to get. enter image description here


Solution

  • Not sure whether it is optimal solution, but it works:

    enter image description here

    while (notDone()) {
      moveForward();
      if (isPathLeft()) {
        if (isPathForward()) {
          if (isPathRight()) {
            turnRight();
          } else {
            turnLeft();
          }
        } else {
          turnLeft();
        }
      } else {
        if (isPathRight()) {
          turnRight();
        }
      }
    }