CS 5010: Problem Set 04: Working with Lists

Out: Monday, February 8, 2016

Due: Monday, February 15, 2016 at 5pm EST

Corrected: Tuesday, February 9 (to correct references to dx and dy, which should have been vx and vy)

The goal of this problem set is to help you design functions that deal with lists, and with the Iterative Design Recipe.

You must use the HtDP Beginning Student Language to solve the problems.

For these problems, download a copy of extras.rkt and put it in the folder with your solutions. Then import this library by including the line

(require "extras.rkt")
at the top of your file with the other requires. Then, for each problem, put in lines that say
(provide function)
for each deliverable function, as you have done on previous problem sets. This will allow our testing framework to import your file and do automated testing on it.

Remember that you must follow the design recipe. Your deliverables include the data definitions (including interpretation and templates), contract and purpose header, code, and tests. Be sure to sync your work and fill out a Work Session Report at the end of every work session. Use the Work Session Report for PS04.

Note: For all universe programs, you may assume the mouse is never dragged or moved outside of the canvas. Once the mouse enters the canvas, if the mouse ever leaves the canvas, then the behavior of your system is unspecified.

  1. (screensaver-3). The physics marketing department at a nearby university wants you to improve the screensaver you wrote for problem 2 of Problem Set 03 in these ways:

    The screensaver is paused at first, as in Problem Set 03. The situation shown in the following image was created by hitting the "n" key four times to create new goofballs, selecting the leftmost goofball and hitting the "left" and "up" arrow keys ten times each, and selecting the second goofball from the left while hitting the "right" and "down" arrow keys ten times each:

    demo of n and arrow keys

    Unpausing the world shown above results in this motion:

    demo of perfect bounces

    You are to deliver a file named screensaver-3.rkt that provides the functions listed below. Note that screensaver, initial-world, world-after-tick, world-after-key-event, and world-after-mouse-event implicitly refer to the specification above, so they behave differently in screensaver-3 than in screensaver-2 even though their contracts and purpose statements read the same as before.

    ;;; screensaver : PosReal -> WorldState
    ;;; GIVEN: the speed of the screensaver, in seconds per tick
    ;;;     (so larger numbers run slower)
    ;;; EFFECT: runs the screensaver, starting with the initial state as
    ;;;     specified above
    ;;; RETURNS: the final state of the world
    ;;; EXAMPLES:
    ;;;     (screensaver 1) runs the screensaver at normal speed
    ;;;     (screensaver 1/4) runs at a faster than normal speed
    ;;; initial-world : Any -> WorldState
    ;;; GIVEN: any value (ignored)
    ;;; RETURNS: the initial world specified for the screensaver
    ;;; EXAMPLE: (initial-world -174)
    ;;; world-after-tick : WorldState -> WorldState
    ;;; GIVEN: any WorldState that's possible for the screensaver
    ;;; RETURNS: the WorldState that should follow the given WorldState
    ;;;     after a tick
    ;;; world-after-key-event : WorldState KeyEvent -> WorldState
    ;;; GIVEN: a WorldState and a KeyEvent
    ;;; RETURNS: the WorldState that should follow the given WorldState
    ;;;     after the given KeyEvent
    ;;; world-after-mouse-event
    ;;;  : WorldState Int Int MouseEvent -> WorldState
    ;;; GIVEN: A World, the x- and y-coordinates of a mouse event, and the
    ;;;     mouse event
    ;;; RETURNS: the world that should follow the given world after the given
    ;;;     mouse event.
    ;;; world-goofballs : WorldState -> ListOfGoofball
    ;;; GIVEN: a WorldState
    ;;; RETURNS: a list of the goofballs present in the WorldState
    ;;;     (without goofballs that have been deleted using the "d" key)
    ;;; world-paused? : WorldState -> Boolean
    ;;; GIVEN: a WorldState
    ;;; RETURNS: true iff the WorldState is paused
    ;;; goofball-selected? : Goofball -> Boolean
    ;;; GIVEN: a Goofball
    ;;; RETURNS: true iff the given Goofball is selected
    ;;; goofball-radius : Goofball -> Integer
    ;;; GIVEN: a Goofball
    ;;; RETURNS: its radius, in cm
    ;;; goofball-x : Goofball -> Integer
    ;;; goofball-y : Goofball -> Integer
    ;;; GIVEN: a Goofball
    ;;; RETURNS: its corresponding x or y coordinate, in cm
    ;;; goofball-vx : Goofball -> Integer
    ;;; goofball-vy : Goofball -> Integer
    ;;; GIVEN: a Goofball
    ;;; RETURNS: its corresponding vx or vy velocity component, in cm/tick
  2. (screensaver-4). The physics marketing department thinks your screensaver would be more exciting if goofballs occasionally blew up, and the physicists are afraid that's going to happen in their laboratories anyway, so your Screensaver 4.0 adds this new feature:

    You are to deliver a file named screensaver-4.rkt that adds this behavior to the screensaver and world-after-tick functions. You should provide the same thirteen functions you provided for screensaver-3.

Last modified: Tue Feb 09 2016