☰ Year plan · Communication Technology

Code, mazes and flowcharts

Week 27 · Theme 4, Lesson 6 Principles of Programming · 3 lessons
2

Maze instructions

ICT P4 Term 2, Theme 4: pp. 66–69
GoalWrite and follow maze instructions with the number of squares and the direction, and put program steps in order.
New words
maze · a path with walls and turnsdirection · the way you movesequence · steps one after another in orderbug · a mistake in a program; fixing it is called debugging
Explanation

A maze is a path with walls and turns. To write instructions for a maze, say how many squares to move and in which direction: forward, turn left or turn right. Computer programs are instructions of this kind, and the steps must come in the right order: if you turn before you move, the robot ends up somewhere else. You can write in short: F for forward, L for turn left, R for turn right, and a number for repeats, such as F3 for three squares forward. Test your instructions by tracing them with your finger on the paper; if the robot hits a wall, find the wrong step and fix it. A mistake in a program is called a bug, and fixing it is called debugging.

Worked examples
StepCommandMeaning
1F3forward 3 squares
2Rturn right
3F4forward 4 squares
4Rturn right
5F3forward 3 squares
The instructions for the maze in the picture: forward 3, turn right, forward 4, turn right, forward 3. The robot reaches the flag without touching a wall.
looksruns to the ballpicks it upbrings it back
A dog fetches a ball for a girl. The program in order: the dog looks around, then runs to the ball, then picks it up, then brings it back to the girl.
Karim wrote: forward 2, turn left, forward 3 to reach the flag on the right. The flag is on the right, so left is a bug. Karim fixed it: forward 2, turn right, forward 3.
Class activity

Make a maze. On 6 × 6 squared paper, draw a path with walls (thick lines or shaded squares), a robot at the start and a flag at the end. On a separate paper, write the instructions with F, L, R and numbers. Swap with a partner, who follows them with a finger. Did they reach the flag? Fix any bugs together.

Practice
1
The robot starts on the bottom-left square facing up. It follows: forward 3, turn right, forward 2. Where does it stop? Say the letter.
ABCD
2
Write the commands (F, L, R) to move a robot up 2 squares and then right 3 squares.
3
Put in order: A walk to the postbox, B write the letter, C put the letter in the box, D put it in an envelope.
4
What is a bug? How do we fix it?