CS 536 (F03) Homework 4: Continuation-Passing Style

Due: October 27 in class (hardcopy)


Assignment Goals


The file mastermind.ss contains the Scheme code to play a simplified version of the game Mastermind. In Mastermind, one player picks a sequence of 5 colored pegs and the other player has to guess the peg colors (in order). After each guess, the first player indicates how many peg colors were correct. The game stops when the second player guesses the correct sequence. (This version is simplified because it reports only the numbers of pegs in the correct positions; the real game also reports how many peg colors are in the solution but in the wrong positions.)

Convert the functions in the mastermind.ss file into CPS (all the user-defined functions minus match?, which you can treat as a primitive). Do not convert calls to functions other than those defined in the file (ie, treat any Scheme-defined functions as primitives). Include correct contracts on all of your converted functions.

If your converted version is correct, a user should not see a difference between playing my original version and your new version (on the same inputs, of course). You can test your work by defining the CPS-ed functions with define-script instead of define (the define-script construct is provided at the top of the mastermind file).

(Side note, not part of the assignment: if you want to have fun with the Scheme web server, look up web-server in the DrScheme help system and try to port the mastermind game to the web using send/suspend.)


Back to the Assignments page