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:

  1. Trace the path on the screen with your finger, from the dog to the goal.
  2. Split it into straight sections. Count how many tiles each section has.
  3. At every corner, say which way the dog is facing and whether it should turn left or right.
  4. 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

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

4/7