300000
English | Français | فارسی | 中文 | Українська | Azerbaijani | ខ្មែរ | Tiếng Việt | Bahasa Melayu | Deutsch | O'zbek | РусскийTurtle Walk
Total number of wins: 215470
What is Blockly?
Blockly is a visual way to build code with blocks. It is a great way to learn to code and to make good code. You can read more about it here. You can also try Blockly games for kids here.
How do you play?
Here, you will make code to move the turtle to its pond. To do this, you use your mouse to drag blocks from the grey box in the middle, and connect them to the start block. When you hit 'Run', it runs the code you have made under the Start block. Click on the Solution button to see one of the possible solutions to the puzzle, not necessarily the shortest one.
How do you win?
You win when your code moves the turtle to its pond. The game is harder when you have to do this with a limited number of blocks.
For Beginners
What is code?
"Code" may sound hard, scary, or mysterious, but it isn't.
In fact, it's a safe bet that you use code all the time! If you have ever used an app, played a game on a screen, clicked on a button, then you have used code. Code is just a list of instructions that your device (phone, tablet, computer, console) knows how to read and follow.
Blockly lets you make code and play with coding principles like variables, functions, loops, and more. These are the same ideas that computer programmers and app/game developers use in their jobs every day.
What is "good" code?
First, code is good when it does what it should! This means it is "correct". In this game, your code is "correct" when the turtle gets to the pond. However, there is more than one "correct" way to do this. Let's say the turtle needs to go in a straight line to get to the pond.
Here is one correct code:
Start:
⇧ go forward ⇧
⇧ go forward ⇧
⇧ go forward ⇧
⇧ go forward ⇧
⇧ go forward ⇧
Is this code correct?
Yes, the turtle will get to the pond, so it is correct.
Is this the best code for this task?
No. Good code should also be efficient : it should do the task in as little code (the least blocks) as possible. The turtle should also take the most straight forward route. Of course, there is just one route at the moment, but as we will see in the next example, there is sometimes more than one short answer.
How can you do the same task with less blocks?
The loop block will repeat what you put inside it, as many times as you want.
How can you use a loop to do the same thing?
Better code will look like this:
Start:
↺ repeat 5 time(s) ↺
⇧ go forward ⇧
This code is better in other ways. Do you see how? Let's say instead of the pond being 10 steps away, it is 100 steps away.
What do you need to change to move the turtle 100 steps instead of 10?
Instead of adding 90 times the block "go forward", you only need to change one thing: the number in the loop block. This code is good because it is correct, more efficient, and it is easy to fix/change.
Start:
↺ repeat 100 time(s) ↺
⇧ go forward ⇧
What type of loop block would scale up even easier than the "repeat" loop block?
The "do until" loop block. This scales up easier than the repeat block because for 5 steps forward or 100 steps forward or even 1000 steps forward, the code would be the same:
Start:
↺ until pond ↺
⇧ go forward ⇧
Another example: Can you make this code better?
Here, the turtle needs to go up a "staircase" to make it to the pond. Below is some code to get him there. It is correct, but it is not very good. Can you make it better? Remember, good code should be correct, efficient, and easy to fix/change.
Start:
⇧ go forward ⇧
← turn left ←
⇧ go forward ⇧
→ turn right →
⇧ go forward ⇧
← turn left ←
⇧ go forward ⇧
→ turn right →
⇧ go forward ⇧
← turn left ←
⇧ go forward ⇧
Answer
In the code, we repeat the blocks "go forward + turn right + go forward + turn left" over and over. The code will be shorter and more efficient if we put these blocks in a loop.
Start:
↺ until pond ↺
⇧ go forward ⇧
← turn left ←
⇧ go forward ⇧
→ turn right →
How can you adapt this code?
Here is a slightly different staircase. How can you change your code to use it here?
Answer
You could keep your old code: it will do the same thing, and the turtle will still get to the pond. In this case, the turtle will try to move up and hit a wall, then keep moving. But the turtle takes a more roundabout route, trying to move up when it can't. Instead, you could add "go forward" twice inside the loop, as shown below. As you can see, in this version, having the shortest working code is not neccessarily the best solution, as the turtle takes longer to get to the pond.
Start:
↺ until pond ↺
⇧ go forward ⇧
⇧ go forward ⇧
← turn left ←
⇧ go forward ⇧
⇧ go forward ⇧
→ turn right →
Summary
Have fun making code with Blockly! Make sure to try to make good code that is correct, efficient, and easy to change or fix.
General Strategy
Start by programming the path with only simple directional steps (i.e. go forward, turn).
Then, check for repeated sequences that can be put into loops. If sequences are similar but not identical, check whether steps could be added to the shorter sequence with no effect, like banging into the wall so that these now equal sequences can be replaced by the same loop, executed as many times as necessary.
Loops
There are 2 types of loop blocks in Turtle Walk.
Repeat [X] time(s)
The loop is executed a fixed number of times, no matter what happens while executing it.
Until Pond, Do...
The loop is executed until the turtle gets to the pond.
Nesting
You can nest loops inside other loops, or even an If...Then...(Else) condition inside a loop.
Tricks to Need Fewer Blocks
To make better, shorter code, try the following (Click for examples):
If actions repeat, put them inside a loop.
In Walk 3, how can you use a loop to use fewer blocks?
Use a loop to repeat the actions "go forward + turn left + go forward + turn right".
Move in Spirals
Walk 8 can be solved with only 4 blocks. How?
To get to the pond, the turtle only really needs to go forward and make right turns, and these actions can be nested inside repeating loops. It doesn't matter if the turtle turns right and tries to run into the wall the first time : the following times it turns right, it will be able to move forward. We can think of this movement as a spiral, turning only in one direction (right or left) and moving forward.
Move in Staircases
Walk 9 can be solved with only 5 blocks. How?
The turtle needs to get from the lower-right corner to the upper-left corner. It cannot travel diagonally directly so it must follow a staircase pattern (in this case left, up, left, up). Even if the path to cross is not a perfect staircase, this will work. Again, it does not matter if the turtle hits walls along the way.
Combine Spirals and Staircases
Walk 12 can be solved with only 9 blocks. How?
First, follow a "Spiral" pattern. That is, inside a loop turn in one direction (right) and move forward as much as possible (choose a high number, here 5 works -- again, it does not hurt the turtle to hit a wall).
Now, the turtle can follow a "Staircase" pattern, even if the path to the pond is not a perfect staircase-shaped path. Repeatedly move left and up to reach the pond.
Use the "if path" blocks.
Walk 5 can be solved with only 4 blocks. How?
Combine the "do until pond" block with "if path right" block so that the turtle turns right when it can but otherwise keeps going forward.
Different Challenges
Please try challenges from our wide range of walks. Some of them have just a single corridor, while others branch. Some have traps and connected doors, keys to unlock doors, open spaces with obstacles, or mazes to cross.
Some Turtle Walks Look Like Mazes
For example, Walks 36, 44, 48 are very simple mazes.
Imagine you are thrown into a maze where the walls around you block your sight -- what is an escape strategy you can apply?
A simple strategy is to follow either the right or left wall.
How can you program such a strategy?
Hint: It needs only 6 blocks, we will let you figure it out.
For some Walks, following one wall leads the turtle into a trap whereas the other leads it to the pond, eg. Walk 44.
When does this strategy fail completely?
An example is Walk 10. Whether the turtle follows the left or right wall, it will never reach the pond.
What is the mathematical issue?
This method fails when there is a closed loop, and the turtle is inside the loop and the pond is outside or vice versa. In either case, the turtle will never reach the pond when following one wall.
What can you do when this strategy fails?
In these cases, you can try to perform other steps before following a wall, or switch walls, or follow the wall for a time and then perform some other steps to reach the Pond.
Do you see walks that can be programmed this way?
Follow or subscribe for updates: