Controlling the Fish

This lab, you will control a fish to finish a maze to find the treasure! Instead of using the usual commands, to control this fish we want you to use special functions we created just for the fish. These functions are found in the purple More Blocks section. This means:

Completing the Lab

  1. Open the Lab: Click here to open the Scratch project.
  2. Create a turnRight function: Technically you could solve the maze with left turns alone, but let's not run the poor fish into more walls than necessary. Use the More Blocks tab to create a new function called . Add code to the function definition to make the fish turn right by 90 degrees when is called.
  3. Understand the tools to solve the maze:
    • In order to solve the maze, you now have , , and functions. These control the movement of the fish.
    • After you call , we set a variable for you to indicate if moving forward hit a wall or not.
      • is set to yes if the wall was hit
      • is set to no if the wall was NOT hit
  4. Think about solving a maze:
    • Imagine the fish always keeps its right "hand" (technically a fin, but we will pretend the fish has hands) on the wall.
    • If you do this (and assume the sharks are a wall), you should expect the fish to take the path in this diagram.
    • By following the wall, the fish exactly follows the following rules:
       
      • Keep moving straight as long as there is a wall to my right. I can find out whether there is such a wall by turning right and trying to move forward. If I run into a wall, I must proceed in my previous direction. (If you want to be particularly clever, you can define a separate function to test the presence of a wall to the right)

      • If I find that there is no longer a wall to my right (aka I don't run into one after trying to turn right), then I will move ahead in the new direction (which, of course, constitutes a right turn from the original direction)

      • If I decide to move straight and run into a wall there as well, then I must try to go left instead. So I'll turn left and try to move ahead.

      • If I run into another wall to my left, I obviously got myself stuck and should just turn around. Since I just came from there, I should have no problem going back.

    • Remember: You can tell if this fish hit a wall by checking the variable. If the variable has a value of yes then the fish hit a wall the last time was called. If the variable has a value of no then the fish did not hit a wall the last time was called.
  5. Complete the program: Using what you know about Scratch, complete the logic described above inside of Scratch to allow for the fish to reach the treasure!

Submission

To submit your lab, you must download the project to your Desktop and upload it to the CS 105 website. Click here to upload your Scratch file to the CS 105 website