COMP 210, Spring 2001
Homework 10 : Caves; Jails
Program due Nov.14 (wed), at start of class.

Do not use set! for this assignment.

What to show for test cases, in functions that are primarily called for their side-effect? What do you do to see if your function is working? Presumably, you look at a room or player, you call swap or leave, and then look what the (appropriate field of the) room or player looks like now. (Note that often it is convenient to have a function w/ side-effects return not (void), but rather (one of) the structures being modified.) You need only show evidence of doing this; we don't need to see the actual values.

Your solution file: Make sure a copy of your solutions is on your owlnet account in your class sub-folder comp210/hw10.ss, so that if necessary the labby can open and run your program.

You are NOT required to show the template for your programs (woo-hoo!). However, your functions should still follow the template, as appropriate. And of course, each function should still have a contract and purpose, and reasonable test cases.

Before you tackle the homework, remind yourself of our General Advice, Advice on Homeworks (in particular: staple and provide questions), and the Grading Guidelines.


  1. (14pts) In this problem, you will implement a simple maze navigation game. The maze is a collection of caves. Each cave has a name, and may contain one item, e.g., a loaf of bread, a compass, a picture of president Gillis, etc. It also has any number of tunnels, leading to other caves. A player can wander from cave to cave and can carry along one item, perhaps dropping it to pick up a new item later. (A player can type in commands to the program.) Here is a sample dialogue:

    You are in Lovett-Hall.  It contains a-file-cabinet. 
    What would you like to do next? inventory
    You are carrying shoes.
    What would you like to do next? swap
    You just put down shoes and picked up a-file-cabinet.
    What would you like to do next? inventory
    You are carrying a-file-cabinet.
    What would you like to do next? leave
    There are 3 exits:
      east-door
      west-door
      stairs-up
    Which one would you like to take? 2
    You are in main-quad.  It contains willys-statue. 
    What would you like to do next? quit
    Bye!
    

    Stop. Think to yourself, and then discuss with your partner, what sort things are in the above problem description, which you will need to model in your program. What are appropriate data types for them? Remember to identify small sub-tasks, and work them out, before trying to solve all the rest of the problem.

    After thinking about this independently, and writing down some data descriptions, go ahead and read the rest of the problem guide, at http://www.owlnet.rice.edu/~comp210/01fall/Homeworks/Hw10/cave-guide.shtml. (which does nothing but give guidance about modeling and implementing the game). But the initial thinking about the game is the most important, most creative, and most difficult part of programming;

    For fun This problem is open-ended and flexible. The design of the dialogue is up to you. You are in control of how you output descriptions of items, caves, or connections, if you choose to do so. It is acceptable to implement the minimum described above, but don't feel constrained by this standard; if you implement more, tell us. Be creative!

  2. (6pts) In the kingdom of Tuhundredtenia, the jail system is extensive, with 200 cells all in a row. Each cell's door has a key, which when turned toggles the door's lock. That is, if the door was unlocked, then turning the key locks it; if locked, then turning unlocks it.

    The Royal Jailer has a curious habit: Every evening, he turns the key in every single door -- numbers 1 through 200. Then, he goes back and turns the key in every other door -- numbers 2, 4, 6, ..., 200. Then, he goes back and turns the key in every third door -- numbers 3, 6, 9, ..., 198. And so on, until he finishes by turning the key in every 200th door (just number 200). After that, he falls asleep, and anybody in an unlocked cell can escape during the night. (At the start of the evening, all cells are locked.)

    You and a baker's dozen of your friends have been framed, and falsely convicted of Meandering with Intent to Jay-walk, and are scheduled to be executed at dawn. Fortunately, each of you can name which cell to be locked away in. Which cell numbers do you-all ask for?

    Hints:

    To think about: Once your program tells you the answer, can you augment this with an explanation for the particular answer? (This is a nice illustration of the difference between knowing an answer, and understanding the answer.)


1 Yes, gifs and jpegs are plain old values in DrScheme just like numbers and booleans. Select "Edit : Insert Image...". Note, however, that saving a file with an inserted image cannot be opened in any application besides drscheme. [back]

2 While this skip-a-location approach isn't usually needed for vectors, the numeric properties of the jailer's walk make it convenient in this case. To think about: What is the extra space-overhead incurred by this approach? Is it significant? [back]