15110 Fall 2011 [Cortina/von Ronne]

Programming Assignment 1 - due Tuesday, September 6

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. For this assignment, you will play the Light-bot 2 game in order to solve seven puzzles (four worth 1 point each and three worth 2 points each). In the Light-Bot game, puzzles are solved by programming the robot "Lightbot" so that when Lightbot is run, he lights up all of the pulsating blue tiles, turning them to yellow.

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:

  1. information on representing Lightbot programs textually,
  2. the puzzles you are required to solve,
  3. instructions for testing your lightbot files, and
  4. instructions for submitting your solutions.

Representing Lightbot Programs Textually

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

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 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 the Light-Bot puzzles below. Specifically, you should create a text file for each puzzle consisting of four parts (a header, a main method, a function 1, and a function 2). These parts should be separated by blank lines.

The header will consist of three lines. The first of which, will begin with "Name:" and followed by your name. The second will have "15-110". The third will have "Section: " followed by the letter for your lab section.

For each procedure, 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", "yellow", or "purple". For example, the command-icon would be written in this textual form as the line "jump if blue".

Name: Jeffery von Ronne
15-110
Section: Z

main:
f1
left
f2
left
left
step
light
step
light

f1:
light
step if purple
jump if blue
break if yellow
f1

f2:
step
light
step
light
right
f2 if yellow
Figure 1 A Light-bot game solution and its corresponding text file

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 written.

The Puzzles

  1. For 1 point, solve the following Light-Bot puzzle, transliterate your Lightbot program it into the textual representation described above, and submit your solution as a text file named "puzzle1.lb". (Note that the file extension uses the letter l, not the number 1.

    Play puzzle1

  2. For 1 point, solve the following Light-Bot puzzle, transliterate your Lightbot program it into the textual representation described above, and submit your solution as a text file named "puzzle2.lb".

    Play puzzle2

  3. For 1 point, solve the following Light-Bot puzzle, transliterate your Lightbot program it into the textual representation described above, and submit your solution as a text file named "puzzle3.lb".

    Play puzzle3

  4. For 1 point, solve the following Light-Bot puzzle, transliterate your Lightbot program it into the textual representation described above, and submit your solution as a text file named "puzzle4.lb".

    Play puzzle4

  5. For 2 points, solve the following Light-Bot puzzle, transliterate your Lightbot program it into the textual representation described above, and submit your solution as a text file named "puzzle5.lb".

    Play puzzle5

  6. For 2 points, solve the following Light-Bot puzzle, transliterate your Lightbot program it into the textual representation described above, and submit your solution as a text file named "puzzle6.lb".

    Play puzzle6

  7. For 2 points, solve the following Light-Bot puzzle, transliterate your Lightbot program it into the textual representation described above, and submit your solution as a text file named "puzzle7.lb".

    Play puzzle7

New: Lightbot Testing Tool

We have created a set of tools for checking for common problems in the formatting of .lb files. On an Andrew Linux machine (e.g., in the Gates Hall Cluster), the tool can be used with the following procedure:

  1. Open up the "Terminal" program under "Applications". This will give you an shell in which you can type commands and the system will respond.

  2. If you put your puzzle?.lb in a directory other than your home directory, use the cd command to change the shell in the terminal window to use that directory as its "current directory." (If you, however, put your puzzle?.lb files in your home directory, you do not need to do anything.)

    The ls command can be used to list the files in the current directory. Use the ls command (type ls and then enter) to check whether you've current changed the current directory to the one that contains your puzzle?.lb files.

  3. Copy your checker tools to the current directory, using the command (including the "."):
    cp ~vonronne/public/15110/*.py .

  4. Check each of your Lightbot files by using python to execute the corresponding checker:

    python lb-check1.py
    python lb-check2.py
    python lb-check3.py
    python lb-check4.py
    python lb-check5.py
    python lb-check6.py
    python lb-check7.py

    For each of the seven lb-check programs, the output will be look like the following if your Lightbot file has no formatting errors:

    running light-bot checker
    note: resolving problems early in the code may fix other problems, so start at the top and go down
    done checking main function
    done checking f1 function
    done checking f2 function

    Otherwise it will give you an error message, indicating what kind of problem your code has.

If you are not using the Andrew Linux environment, you may still be able to run the Lightbot format checkers (lb-check1.py, lb-check2.py, lb-check3.py, lb-check4.py, lb-check5.py, lb-check6.py, lb-check7.py), if you have Python installed on your computer. We, however, are unable to provide detailed instructions for using them on other computers.

Submit Your Assignment

Create a zip file called prog-assgn-1.zip that contains your seven text files, and submit it for grading using the handin instructions.