Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

The Big Run

Time for the big run. These courses turn both ways, left and right, and there are bones on them again. The last map is a real obstacle course: the dog weaves between hedge poles, runs around the field and finishes in the middle of it.

The editor holds the program from the last exercise. Run it and watch the first map. At the first corner that turns left, the dog turns right twice and finds the path it came along. It runs back into the box, out again, back to the same corner, and so on, until the editor stops the program because it ran for too long. Turning right only worked while every corner turned right.

The task. When the dog can't go straight ahead, it has to choose which way to turn. Change the program so that the dog runs every course, picks up all the bones and finishes at the goal. Keep an eye on the box too: the dog still has to get out of it on every map, whichever side the way out is on.

A tip: the dog can't know which way a corner turns until it gets there. But there, it can look to its left and to its right. What does it need to know to choose? And what if the way out of the box is behind it?

That's the whole obstacle course. Your program doesn't know a single course in advance, yet it runs them all: it gets out of the box whichever way the dog faces, turns the right way at every corner and picks up every bone. And it fits in about a dozen blocks. It holds almost everything this course has taught you so far: loops with conditions, the dog's senses, decisions with If and else, and maybe not too.

Look at the part that turns the dog toward the path. It's a small algorithm of its own. If it were a single block, called "face the path", say, the program would read like a sentence: until at the goal, face the path, take a step, and if there's a bone here, pick it up. In the next lesson, Functions, you'll learn to make blocks like that yourself.

Instructions

  1. 1

    Pick up all the bones on all three maps.

  2. 2

    And finish at the goal.

Back

3/3

  1. 1. Warm-Up
  2. 2. Treats on the Course
  3. 3. The Big Run
Next

Try it yourself

Do this exercise right here in your browser. No account needed.