CS212 Problem Sets
FAQ - Problem Set 5

LAST UPDATE: Wednesday, January 19, 2000 11:35 PM

Problem 1

How do we hand this problem in?

Don't try to submit it online with the rest of the problem set. You should write out your solution neatly and hand it in at section on the due date.
NOTE: Problems 2-6 are due by 2pm, but this problem may be turned in by the end of section on Monday April 19th. No late submissions will be accepted.


Problem 2

Should I use set-car! and set-cdr!, or should I use (set! (head p) v) and (set! (tail p) v)?

Please use (set! (head p) v) and (set! (tail p) v), they are just easier to read (and readability is important - if you hadn't figured that out yet).


Problem 3

How do I know my definition of dequeue works?

After evaluating (load ps5), just evaluate your definition of dequeue. This will replace our definition of dequeue from the binary. If the game still works after you load your definition of dequeue, then your definition probably works.
ALTERNATIVELY: If you want to rigorously test dequeue, you can load queue.ss and your definition of dequeue. Then using some of the tests provided in tests.ss (found in the ps5 folder with the rest of the sources), you can more thoroughly test your dequeue.

Do I need to provide output with my solution?

You do not have to provide output.  Remember this is a really short definition, so it will be graded mostly on whether it works or not.


General Tips

I'm getting strange errors, and I'm sure my code is correct. Do you have a bug in your code?

Chances are: the answer is no. Have you updated the binaries. Check the Update Information page to do this.

Do we have to....?

If you are thinking about doing more in a problem than we ask (for instance, you want to give ducks a little more intelligence) then by all means go ahead. Be warned though, we are giving you this bit of freedom so you can flex your programming muscles, but in the end, we are grading the problems to see that you answered the question.

How is the plan for an automated animate inserted into the event queue?

When evaluating make, Swindle calls a generic function initialize. The problem set, in animated.ss, overloads the initialize method. Here you can see how an animate loop is created such that their plan is executed on a determined interval. The initialize method also finds what time the first plan is executed.

What are some things I should watch out for in my code?

What are some ways to debug my code, considering it's time consuming to play the game?

There are several ways you can debug problems four through six, that don't necessarily involve playing the game. For functions like find-path, you can simply run the function without playing the game. With the current map, evaluating this should produce the following output:

==> (map nick
     (letrec ((iter (lambda (x y)
                      (if (eq? x y)
                        (list x)
                        (cons x (iter (find-path x y) y))))))
       (iter loc:station loc:aaaagh)))

(station university french forest valley cave bridge lake aaaagh)

The wheelbarrow can effectively be tested by just playing the game, but it's a little harder to keep watch on the reaper and ducks. So a clever way to test your code is to run the server. See the Just for Fun section for information about running the server.

Because running the server essentially makes the clock tick faster, the ducks should die in real time. Notice how you have two views of the game - one from the server, and the other from the client. The server allows you to evaluate Swindle expressions, while the Client lets you type in game commands.

You can start the server and join the game - hang out in the pub and see if the grim reaper starts to get drunk. When you run the server, you have control over the game without having to play it. So if you want to check the location of the reaper, while the server is running, just evaluate (name (location chr:reaper)). Additionally, you can change the state of the game and see if the grim reaper reacts. For instance, try killing Bill Gates, by evaluating (kill chr:bill), and see if the reaper does in fact ignore him. You can also check the contents of the reaper's wheelbarrow.

If you run the server to test your code, make sure that you are thorough, and explain what you did to test in the short sentences you have to write.


Problem 4

You tell us to define a <mortal> class, but can we define a <duck> subclass of mortals?

Defining a <duck> subclass of <mortal>, could be very useful.

Should this <duck> class have the plan, or should the <mortal> class have it?

Ducks have a very specific dying ritual...
Do all mortals have this ritual?

When a duck produces a holy hand grenade, should it be the same as the one found in Camelot?

It should have the nick-name 'grenade, but other than that, you may be creative.

Do ducks have to run away if a person is in the room?

Ducks do have to run away if a player (not an animate, sorry for the confusion) enters the room.  This is the only steadfast rule. Any extra implementation features to ducks will be left to your imagination. It is not a requirement that a duck runs away if someone is in the room.

How do I get a fifty-percent probability for a duck reproducing?

You should use the random built in function for this - (random N) gives you a random integer in the range of 0 to N-1, so (zero? (random 2)) will be #t with a 50% probability.


Problem 5

Should our functions work for any <wheelbarrow> instance?

Yes.

I've already written look-in-cart, and you changed the requirement. Do I have to rewrite this?

If you're pressed for time, don't worry about it. But changing your code to conform to the new requirement is trivial, so try to change it if possible.

What should the command format be for the put-in-cart, get-out-of-cart, and dump cart be? (i.e. can I do put <something> in <wheelbarrow>?)

You can do whatever you think is understandable to the player. You should document the syntax for the player so when they type help, they will see the syntax of the command.

When defining the command for dump, should the player specify which adjacent location to dump the wheelbarrow in, or should the adjacent location be random?

It makes sense to let the player choose the adjacent location. A possible syntax for the dump command would be: dump <wheelbarrow> <place>.


Problem 6

Can the reaper reference obj:wheelbarrow?

Yes.

Do I need a <reaper> class?

No.

So you gave us this option to use a queue to find corpses, why?

It makes the code you write easier. Easier doesn't necessarily imply better, so if you want to write the better solution using breadth-first-search then go ahead. We will consider both solutions equally correct. (Read the Problems page for the details).

Should I memoize the paths that I find with my find-path method?

You should evaluate whether or not memoizing saves you time computationally. For some fairly large graphs, it is possible that memoizing the best path between two points could help. Chances are for the small map we have in this game, it won't help and it's not worth the effort. Besides, an efficient implementation of find-path is fast -- very fast.