One of the main themes of this course is to think computationally in order to figure out how to solve complex problems using principles from computer science. To introduce this main theme, we will play an online game called LightBot 2. The goal of LightBot 2 is to program a virtual robot to light one or more square on a floor that may be uneven or have other surprises.
Light-Bot 2 contains a set of standard levels divided into four categories: basic, recursion, conditionals, and expert. If you have not already, you should go and play the first few levels in the basic, recursion, and conditionals categories of Light-Bot 2 before proceeding.
The rest of this document contains:
In the game, the Lightbot is programmed by arranging icons representing discrete actions onto a grid. The possible actions are:
step | right | left | jump | light | f1 | f2 | break |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
A command (left, right, jump, etc.) can be "colored" so that it only occurs if Lightbot is the given color when it tries to execute that command. For example, the command
will cause Lightbot to jump only if it is currently blue. Otherwise, Lightbot doesn't jump. (You can create a colored command by first dragging the command into the robot's program area and then clicking the multicolor box and clicking the command until it turns into the color you want.)
After the player finishes building the program, they press the "Run" button and watch Lightbot operate under the control of the program. Commands are grouped into three procedures: a "main method", a "function 1", and a "function 2". When executing a procedure Lightbot, generally, executes each command of the procedure left-to-right, top-to-bottom. That is, Lightbot first performs the left-most action in the top row of that procedure, then proceeds performing the actions left-to-right within each row, moves to the left-most command of the next lower row after completing each row, and finally stops when the end of the procedure is reached. (The "f1", "f2" and "break" commands alter the order of execution, but even when such commands are present, this left-to-right, top-to-bottom ordering defines each procedure's "command sequence".)
Although programs can be written in a variety of notations — including graphical ones, like in the Light-Bot online game — it is most common to use represent programs textually. That is, most programs are represented as a sequence of letters numbers, spaces, and other character symbols, arranged according to particular rules that define what sequences are allowed and what they mean. We will see this later for programs written in Ruby, but we can also rewrite our Light-Bot programs in a textual form.
For example, consider the Lightbot puzzle with its solution program and the corresponding text file shown in Figure 1 below.
It is in the textual form that you are required to submit your solutions to Lightbot puzzles. Specifically, you should create a plain text file (ending with an extension of .txt) for each puzzle consisting of three parts (a main function, a function 1, and a function 2). These parts should be separated by blank lines.
For each function, begin with a line containing "main:", "f1:", or "f2:", respectively, and then continue with a list of commands for that procedure. (If there are no commands for f1, put a blank line immediately after the "f1:", and continue with the next procedure. If there are no commands for the f2 procedure, simply end the file after the "f2:".) The commands for each procedure should be listed one per line so that reading them top-to-bottom results in the same command sequence as reading the commands left-to-right, top-to-bottom in the Light-bot game. Commands that would be colored gray in the Light-bot game should consist of a single word in all lowercase characters: "step", "right", "left", "jump", "light", "f1", "f2", or "break". Commands that would be colored in the Light-bot game (indicating an action that should only be performed when Lightbot is that color) should be written as three words on a single line. These should be written using one of the command words, followed by the word "if", followed by the color, either "blue", "orange", or "purple". For example, the command-icon:
would be written in this textual form as the line "jump if blue".
![]() |
main: f1 left f2 left left step light step light f1: light step if purple jump if blue break if orange f1 f2: step light step light right f2 if orange |
It is important to follow these formatting requirements precisely, because the course assistants will be using a testing program to automatically grade your Lightbot programs. This testing program will only be able to determine whether your program solves the puzzle if your program is correctly formatted.