Step 5

Creating the main program structure


Coding the “Turn Right Algorithm” is going to take a quite a bit of code, luckily we can utilize custom blocks/functions to help make this a little easier.

Inside the “My Blocks” section. Create a custom block/function called “driveForward”. This function will control how our robot drives forward when we need it to, we’ll work on defining this code in the next page.

After making that block, add the code as shown into your program. Here we have a loop that repeats until the maze is complete (this is shown by the final if statement where it says “if allDone”).

Inside the loop, we also have the code that forms the basis of our algorithm, an if statement that checks if we have a Wall in front of us. If there is (if “Wall” is true), the robot turns left and drives forward, otherwise it turns right and drives forward.