Karel the Robot is a programming environment for learning elementary programming developed by Richard E. Pattis (Karel The Robot: A Gentle Introduction to the Art of Programming. John Wiley & Sons, 1981). Building a Karel world 1. Open the project generate.sb in Scratch and click the green flag. 2. Construct wall segments by clicking in the middle of the square where the segment starts and then in the middle of the square where the segment terminates. Since segments need not be connected, you need to click twice for each segment, even if the new segment is connect to the previous one. When you have finished constructing the walls, click on the X in the lower left corner. 3. Place beepers by clicking on intersections. When you have finished placing the beepers, click on the X in the lower left corner. If you are using the framework that allows multiple beepers on an intersection, the program will prompt you for the number of beepers. If you just press the Enter key or click on the check mark without entering a value, a default value of one beeper is used. An intersection is limited to at most 5 beepers. 4. Export the image of the world by right-clicking on the stage and selecting save picture of stage. Writing a Karel program Karel-frame.sb2 is a framework for writing a Karel program. 1. Open this project in Scratch and save it under a new name so you can use the framework for another program. 2. Change the background to the Karel world you created above: Click on the Stage in the sprite area and then click on the Background tab above the script area. Import the file containing your Karel world. You can delete the previous background by clicking on the X next to it. The sprites Beeper and Checker are used to implement the Karel instructions. Modify the instructions to initialize position of the Karel robot by specifying an avenue, a street and a direction; you can also specify the number of beepers initially in the robot’s bag. The Karel instructions Karel instructions are implemented by Scratch scripts, each of which is run when it receives a message with its name. The instructions are Move, TurnLeft, PickBeeper and PutBeeper. TurnRight is also predefined for convenience. To run an instruction, use the broadcast and wait instruction. For sensing, five variables are defined: frontIsClear, leftIsClear, rightIsClear, nextToABeeper, and Beepers. The first four have the value 1 if what they claim is true and 0 if they are false. For example: The variable Beeper stores the number of beepers in the robot’s bag, and can be used to implement anyBeepersInBeeperBag and noBeepersInBeeperBag by checking if the value of the variable is positive or zero. The conditions facingNorth, notFacingNorth, facingSouth, notFacingSouth, facingEast, notFacingEast, facingWest and notFacingWest are easily implemented using ordinary Scratch blocks. There are three errors conditions: trying to move through a wall, trying to pick up a beeper that is not there, and trying put down a beeper if there is none in the bag. These errors will cause a message to appear and the scripts will be stopped.