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

Fetch First

In these mazes, the dog's owner waits at the goal, and the bone lies further in, behind the flag. Run the program from the last exercise. The dog walks onto the flag, and the program ends: Repeat until at the goal checks before every pass whether the dog is at the goal, and the dog gets to the goal before it gets to the bone. The bone stays in the maze.

The dog has to walk past the flag, fetch the bone and bring it back. That takes two loops, one under the other:

  1. Repeat while not bone here, with one step of the right-hand rule inside, takes the dog past the flag to the bone. Under the loop, Pick up bone picks it up.
  2. Repeat until at the goal, again with one step of the rule inside, takes it on from the bone. The dog keeps following the wall, and the wall leads it back to the flag.

Both loops need the same six blocks of the rule. You could build them twice, but the program would then have 17 blocks, and this exercise allows 14. A function lets you build them just once: put the rule under Define step, and both loops call it with the step block. If the rule had a bug, you'd also fix it in one place, and the program reads like its plan: step until the bone, pick it up, step until the goal.

To make the function, drag Define trick into the editor, click its name and type step. Then drag Turn right ↻ out of the loop and under Define step: the blocks under it come along. The column of blocks now has a step block, which calls the function.

The If that checked every tile for a bone isn't needed anymore: each map has just one bone, and the Pick up bone under the first loop picks it up.

Instructions

  1. 1

    Make a function step with one step of the right-hand rule. Call it in Repeat while not bone here and put Pick up bone under the loop, so that the dog picks up the bone on every map.

  2. 2

    Under that, add Repeat until at the goal with step inside, so that the dog walks to the goal.

  3. 3

    Use at most 14 blocks.

Back

3/4

  1. 1. The Maze
  2. 2. Bones in the Maze
  3. 3. Fetch First
  4. 4. The Big Maze
Next

Try it yourself

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