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:
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.
Java URL Encoder/Decoder Example - In this tutorial we will see how to URL encode/decode…
Show Multiple Examples in OpenAPI - OpenAPI (aka Swagger) Specifications has become a defecto standard…
Local WordPress using Docker - Running a local WordPress development environment is crucial for testing…
1. JWT Token Overview JSON Web Token (JWT) is an open standard defines a compact…
GraphQL Subscription provides a great way of building real-time API. In this tutorial we will…
1. Overview Spring Boot Webflux DynamoDB Integration tests - In this tutorial we will see…
View Comments
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.
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
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.
*second dimension :P
[code language="js"]
Maze.turnLeft();
while (true) {
if (!Maze.isWallRight()) {
Maze.turnRight();
Maze.moveForward();
}
if (!Maze.isWallLeft()) {
Maze.turnLeft();
Maze.moveForward();
}
Maze.moveForward();
Maze.checkTimeout();
}
[/code]
This one also works.
[code language="js"]
while (true) {
if (!Maze.isWallRight()) {
Maze.turnRight();
}
if (!Maze.isWallLeft()) {
Maze.turnLeft();
}
Maze.moveForward();
Maze.checkTimeout();
}
[/code]
Cheers
4 lines:
repeat forever
if (wall ahead or (not wall to the left or not wall to the right))
turn randomly
move forward
Your solution doesn't always work. It can get stuck in a loop in the upper right lane
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....:)
i like to use the if - else if - else to its fullest ... and only use statements once ...
[code]
while (true) {
if (!Maze.isWallLeft()) {
Maze.turnLeft("44");
} else if (Maze.isWallForward()) {
Maze.turnRight("61");
} else {
}
Maze.moveForward("1");
Maze.checkTimeout("8");
}
[/code]
reverse if you wish it to follow the right wall instead of the left ...
[code language="java"]
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();
}
}
[/code]
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.