Due Wednesday, May 16 at 11:59am sharp. Late submissions will receive half marks if submitted before July 25 at 11:59 AM sharp.
All work must be submitted to the Marmoset submission system. See the preamble of assignment 1 for more information.
Your module simon.rkt should provide (in addition to simple-simon and press) a function (score) which produces the score of the immediately previous completed game. If no game has been played, it should produce 'undefined. For example, you might test your implementation with the following interaction:
Welcome to DrRacket, version 5.1.3 [3m]. Language: racket; memory limit: 128 MB. > (simple-simon 3) (green yellow red) > (press 'green) ok > (press 'yellow) ok > (press 'blue) lose > (score) 1You should submit only simon.rkt. However, it is strongly recommended that you create a module testsimon.rkt that you use to test your solution before submitting it to Marmoset.
;; (best-score) -- the highest score of any ;; game played so far. 'undefined if no games have been played.Here's a sample interaction:
Welcome to DrRacket, version 5.1.3 [3m]. Language: racket; memory limit: 128 MB. > (simple-simon 3) (green yellow red) > (press 'green) ok > (press 'yellow) ok > (press 'blue) lose > (score) 1 (best-score) 1 > (simple-simon 2) (red blue) > (press 'red) ok > (press 'blue) win (score) 2 (best-score) 2
;; full-simon.rkt plays a simon game consisting of n rounds.
;; The first round requires that the user press a sequence
;; of length 1, the next round a sequence of length 2, and
;; so on to the final round which requires that the user
;; press a sequence of length n. The sequence in each
;; round is a prefix of the same random sequence of colors,
;; each of which is one of ('red, 'blue, 'green, 'yellow)
;; the following functions are provided:
;; (full-simon n) Starts a new game with n rounds and produces
;; a list with one random color -- the sequence
;; that must be pressed in the first round
;; (press c) Consumes a color c (which must be one of 'red,
;; 'blue, 'green, 'yellow) and produces one of the
;; following results:
;;
;; 'win -- the game is complete, and every round
;; has been played correctly
;; 'lose -- c is not the correct color
;; 'ok -- c is the correct color, and the round is
;; not yet complete
;; a list of colors -- c is the correct color, and
;; the round is complete, but the game
;; is not complete. The list of colors
;; produced is the sequence that must
;; be pressed in the next round.
;; (score) Produces the score for the most recently played game,
;; as defined by the formula given in problem 1. Note
;; that for this game maximum_presses is not equal to n
;; (best-score) -- the highest score of any
;; game played so far. 'undefined if no games have been played.
You might test your implemenation with the following interaction:
Welcome to DrRacket, version 5.1.3 [3m]. Language: racket; memory limit: 128 MB. > (full-simon 3) (red) > (press 'red) (red red) > (press 'red) ok > (press 'red) (red red green) > (press 'red) ok > (press 'red) ok > (press 'green) win > (score) 6 > (best-score) 6As always, you are advised to write your own module testfull-simon.rkt and use it to test your solution thoroughly.
Write a test suite for Problem 1. The test suite should include 10 different tests and should be in the form of the example shown in Problem 1. Also, clearly number each test and give a 1 line description of the test. Separate each test with a line of asterisk characters ("*").
Implement simon.rkt as an immutable abstract data type. Your implementation must not use mutation -- set!, mutable structs, and library functions that allow you to write memory are not allowed. Marmoset will do some cursory checks to enforce this rule, but markers will also check manually and cancel the Marmoset score if mutation is used.
Your simon.rkt module should implement the following interface, which is slightly different from that used for problem 2:
;; simon.rkt plays a single round of the "Simon" game
;; provides:
;; (simple-simon n) consumes a positive integer n
;; produces (list seq press-fn)
;; where seq is a length-n sequence of colors
;; from {red, blue, green, yellow}
;; and press-fn is a `press' function
;; ----------------------
;; A `press' function consumes a color c
;; produces (list 'win score) if c is correct and game done
;; another `press' function if correct and game not done
;; (list 'lose score) if c is incorrect
If your implementation is correct, it should work with this implementation of the simon user interface.