Planning the Route
Great, now you can walk and turn. But the longer the path, the easier it is to get a block wrong, and the dog ends up in a hedge. That's why programmers plan a program before they write it.
Imagine guiding a friend over the phone. "Come to me" isn't enough; you have to describe every part of the way: "Walk two steps straight on. Turn right. Walk two steps…" You have to guide the dog the same way. It can't see the green tile; it only knows the steps you give it.
How to do it:
- Trace the path on the screen with your finger, from the dog to the goal.
- Split it into straight sections. Count how many tiles each section has.
- At every corner, say which way the dog is facing and whether it should turn left or right.
- Only now build the blocks, section by section. You can run the program before it's finished to check that the first sections work.
Breaking a big task into smaller parts that are easy to solve is one of a programmer's most important skills. It's called decomposition.
Instructions
Plan the route and get the dog to the goal. The path has five straight sections.
Start programming for free
4/7