Using directional commands to navigate a robot through a simple map or grid.
Imagine you have a robot friend who only speaks 'Code.' If you tell it to 'go to the kitchen,' it just stands there! How can you give it the exact secret instructions to find a snack?
Robots are very smart, but they are also very literal. They don't know what 'over there' means. Instead, they use a Grid, which is a map made of squares. To move a robot, we use three main commands: Move Forward, Turn Left, and Turn Right.
Crucially, a Turn command does not move the robot to a new square. It only changes the direction the robot is facing. Think of it like spinning in circles while standing on one floor tile! To actually change squares, the robot must hear the Move Forward command.
Quick Check
If a robot is facing North and you tell it to 'Turn Right,' which direction is it facing now?
Answer
The robot is now facing East.
Let's move a robot 3 squares ahead in a straight line. 1. Command: Move Forward (Robot moves to square 1). 2. Command: Move Forward (Robot moves to square 2). 3. Command: Move Forward (Robot moves to square 3).
To move to a square that isn't directly in front of the robot, we have to combine moves and turns. This is called Pathfinding. When you plan a path, you must always check which way the robot is facing before you tell it to move. If the robot is facing a wall and you say 'Move Forward,' it will bump its metal nose! We use Turn commands to aim the robot toward the goal before we take our steps.
The robot needs to move 2 squares forward, then 1 square to its right. 1. Move Forward 2 times. 2. Turn Right (The robot rotates but stays put). 3. Move Forward 1 time.
Quick Check
True or False: A 'Turn Left' command moves the robot one square to the left.
Answer
False. A turn command only changes the direction the robot faces; it stays in the same square.
In computer science, we often want to find the shortest path. This means using the fewest number of Move Forward commands possible. To find the total length of a path, we add up all the forward steps. We can write this as a simple math problem. If a robot moves steps, then turns, then moves steps, the total distance is:
A robot needs to get around an obstacle. It takes this path: 1. Move Forward 3 squares. 2. Turn Left. 3. Move Forward 2 squares. 4. Turn Right. 5. Move Forward 4 squares.
Which command would you use to make a robot face a different direction without leaving its current square?
If a robot moves forward 4 squares, turns, and moves forward 5 more squares, what is the total distance?
A robot can move diagonally (like a slide) across a grid using a single 'Move Forward' command.
Review Tomorrow
In 24 hours, try to remember: Does a 'Turn' command count as a square moved when calculating total distance?
Practice Activity
Draw a 5x5 grid on a piece of paper. Place a coin on one square and try to write down the 'code' (commands) to get it to a 'Finish' square on the other side!