CSc 11: Introduction to Computing
Lab work and Assignment #2 (Chapter 2)

After going through the multimedia for Problem Solving Before Programming, you will start solving problems in Knobby's World. In lab, do the following non-written exercises from the book, given again below (you can bring them up in Netscape while you're in lab). Show a Teaching Apprentice that you've got at least as far as the last two exercises. Then go on to the homework exercises below.

Note: Knobby's World has been installed on the LAN. You may also download Knobby's World using a web browser, from the Knobby's World page under my web page. Download it to drive C:\, the root or top directory. After you've got it in C:, use winzip or (pkunzip -d knobby) to unarchive it into directory C:\umach. (You shouldn't need to do this if you are working in the lab or elsewhere on campus.)

Knobby's World laboratory exercises (from The Universal Computer):

Exercise 2.57: Start up Knobby's World. By default, it should load the situation file mountain.sit. By using move and left, navigate Knobby to the other side of the mountain.

Exercise 2.58: How can you instruct Knobby to take three steps backward? When or why might you want Knobby to do this?

Exercise 2.59: How can you instruct Knobby to take three steps forward, pick up a character, and return to his original position?

Exercise 2.60: What happens if Knobby attempts to perform a write at the beginning of a task? Why? How can a Knobby program avoid this behavior?

Exercise 2.61: What happens when Knobby performs a read from a corner that appears not to have a character on it? How can you use this behavior to erase other characters?

Exercise 2.62: Now for some action! Press the reset button, so that Knobby is back where he started, ready to start a task. Knobby's goal is to pick up a copy of the flag, F', climb up to the top of the mountain (where it should find '^'), plant the new flag there, then climb down to the other side of the mountain. What problem solving strategy might you well use to solve this problem?

Exercise 2.63: There is no single command to copy a character from a corner, one at 1st Street and 2nd Avenue, the other at 1st Street and 3rd Avenue. How can he do that?

Exercise 2.65: Without actually doing it, what do you suppose would happen if you sent Knobby to the flag, had him read it, and then copied b2 into b1? Why? Now perform the experiment to see if your analysis was correct. (Don't forget to reset the world first.)

Exercise 2.66: Reset again. This time plant a copy of the flag on top of the mountain, then come back down and erase the (original) flag you've left at the bottom. How can Knobby "empty" board b1 in order to erase the flag? Hint: see exercise 2.61.

Exercise 2.68: Using macros, define instructions right and reverse. (Enter d to define a macro-instruction; enter e to execute it.)  Then send Knobby through the task of planting a flag on a mountain, using your new instructions. (Remember, you perform a left or a move as before; you perform a right or a reverse by pressing e, then telling Knobby which new instruction to execute.)

Exercise 2.69: Now that you have defined macro-instructions right and reverse, define a single new instruction for the complete flag-moving task. (Test it to make sure that it works correctly.) In what sort of circumstances might this new instruction be part of a solution to a still larger problem?

(Show a lab instructor that you have done and understand the above laboratory exercises, before going on to do the homework.)

Homework exercises, in the textbook, The Universal Computer:

a) Do the following written exercises: 2.1, 2.5, 2.6, 2.7 (describe your solution when you hand it in), 2.19, 2.20, 2.36, 2.46 and A.58 (near the end of the book). Use a text editor or word processor to enter your answers into one file.

Write Knobby's World programs for exercises 2.82 and 2.90 (for 2.90, instead of 3+4, show how Knobby solves 2+4). Instructions for handing in these programs are below.

Extra credit: 2.83, 2.84, 2.86 (Knobby's World will let you let create and edit your own situation files--see the World menu) and 2.91 (you can do any of these exercises for extra credit--take your pick!).

Due: Tuesday, September 10, anytime before midnight.

Hand in: Enter all your answers into a single file, using an text editor such as notepad or Word. (You can copy and paste the content of your Knobby's World programs into this one file; just use comments to demarcate each program file within your one big file.) Hand in your homework using the Drop Box accessible via the Tools button for the CSc10 CourseInfo page. Please hand in your assignments in the CourseInfo Drop Box. Once you're in the Drop Box tool, click on the Browse button, then find your file in its folder (if you put it on a floppy disk, it's in A:). When you've selected your file, you should see a directory path to this file next to the Browse button. If it looks right to you, click on the Send File to Instructor button. Then you should see this file listed under Current Files in your DropBox. One of the Teaching Assistants, probably Faisal Khan (fmk2(at)lehigh.edu), will get this file, grade it, and upload his comments to the Drop Box.

If you have any questions about submitting assignments or grading, please send email to Faisal Khan (fmk2). (If you can't figure out how to use the Drop Box, you may just email the assignment to him.)

Hints:

Exercise 2.82 assumes that you use the initial world situation in file morning.sit. (Under the World menu option, select Load, then double click on file morning.sit.)  To create your program, you could copy one of the other Knobby's World programs (ending with extension .kno) to another name, e.g.

      C:\umach>copy square.kno morning.kno

Then load it into Knobby's World (under the Program menu, select Load, then double click on morning.kno), then edit it (under the Program menu, select Edit, then mouse click on the editor window on the right). Use decomposition to break this problem down into smaller pieces that can be defined as instructions, which get called by the top level main instruction or other instructions. Try creating a few utility instructions, such as turning right, or moving a particular number of squares. Comment your code!

Exercise 2.90 only requires that you write a program that adds 3+4, not any two numbers. (Any two numbers is covered in exercise 2.90, which is extra credit.)
Note:Instead of 3+4, show how Knobby solves 2+4. Here are adder23.sit, which sets up the 2+3 problem (two X's, space, then four X's) and adder24.sit, which sets up the 2+4 problem
(two X's, space, then four X's) for 2.90, on my web page.    (You'll also find these situation files on the LAN and CD-ROM.)

For the extra credit exercise 2.83, etc, you'll need to use while loops to generalize your solutions.
See example programs ifwall.kno and loopgoal.kno (with loopgoal.sit) for examples illustrating if and while control structures;
see chapter B at the back of the book for details about if and while control structures.
If for exercise 2.83, your program allows Knobby to jump any SIZE hurdle, you might want to demonstrate this by setting up another situation file.
More extra credit for this--but make sure this is documented!

Regarding Knobby's World programming, a student asks: > How can you break an infinite loop? My program was stuck in > an infinite loop and the only way I could stop it was to quit > the program. Thanks.
Apparently Knobby's World doesn't respond to ctrl-c or ctrl-break.
Here's what works: press ctrl-alt-del (hold down the Ctrl key, then hold down the Alt key, then press the Del key).
Windows will bring up a list of tasks.
Click on Knobby's World, then click on end task.
This may not work right away if you're in a "tight" (fast) loop, so you may have to wait or do this more than once.
BTW, this is how you can kill any task that's not behaving well, under Windows.

Prof. Blank