Problem Set 4

home work!

Programming Language BSL

Purpose This problem set concerns the design of functions on self-referential data definitions in the context of interactive programs.

Finger Exercises HtDP/2e: 133 followed by 127, but read in opposite order; 135, 136, 139, 151, 152, 154, 158, 160, 162, 164, 173; in preparation of the next exam, consider solving any of the extended exercises in chapter 13

image

The General Problem Henry is a hungry guy who loves cup cakes. Fortunately he works at a start up that serves cup cakes every afternoon in their conference room. To save the company the effort of putting all the left-over cup cakes, Henry works his way through all the cup cakes once everyone has left the room. Since eating alone is boring, he tries to plan a short path through the conference room that brings him within reach of all the cup cakes.

After a while Henry’s company discovers that his clean-up action naturally inspires a simple game application. The game accepts a number, creates a conference-room scene with that many cup cakes, and asks the player to “eat” these cup cakes by setting the fewest possible way points. That is, the player’s task is to visit/eat all cup cakes via mouse clicks. Each mouse click sets a waypoint, and once such a waypoint is set, the player’s avatar must travel there regardless of later mouse clicks. The goal is to minmize the number of clock ticks it takes to eat all cupcakes.

For the first issue of the game, the company decides that the avatar travels on a straight line and at a fixed speed [of yeah-many pixels per clock tick] from its current location to the closest next waypoint. Eventually the avatar’s distance is less than or equal to its speed, at which point it just jumps to the waypoint and thus removes it from its list of goals.

When an avatar gets close enough to a cupcake, it eats the cake instantaneously. For our purposes "close enough" means that the avatar overlaps with the center point of the cup cake. To keep things simple, we assume that the avatar cannot simultaneously move and eat cake. The game ends when there are no cup cakes left and the result of the game is the number of clock ticks it took to clean the simulated conference room.

Problem 1 This problem is due on Tuesday, 1 October 2013, 6:00pm

Design a data representation for the HungryHenry game. Then define the main function and write down the wish list of necessary handler functions.

Note Before you proceed to the remaining problems on this problem set, you must get one of the TAs (see General Information) to “bless” this initial design. Edit your design DrRacket, print it, and save the file. Take the print out to a TA during his or her office hours. The TA will inspect your design and either sign/date it—in which case you are free to proceed—or reject it and ask for a revision—in which case you must see the TA with an improved design.

You must turn in your signed contract at the beginning of the Thursday lecture that you attend. The tutors will grade only solution sets with signed and dated designs. Designs that have a late signature (Wednesday or Thursday) lose 20% credit per day. That is, if the assignment’s maximal score is 100%, a design dated Thursday receives at most 60%.

Problem 2 While your wish list from problem 1 cannot contain a function that merely moves an avatar, you know from the problem statement that this piece of functionality is central to the game. The function also happens to encapsulate the most complex piece of domain-specific knowledge, which is why we present its design as a completely separate problem.

Design the function that moves the player’s avatar by a fixed number of pixels D in the direction of the next waypoint. The function consumes a representation of the avatar, a representation of a waypoint, and produces a revised avatar with an appropriate location. Assume that the distance between the avatar and the waypoint is larger than D pixels.

Problem Set 2, problem 4 poses a related problem. The key difference is that HungryHenry calls for a shortening of the distance by a fixed number of pixels while the problem 4 from Problem Set 2 requested shortening the distance by a specific percentage.

Problem 3 Design the remaining handler functions from the wish list of problem 1.

Your program should render the cupcakes, the avatar, and the to-be-visited waypoints. For the version that you hand in, use shapes from "2htdp/image" to render these items. For the version that you play, you may instead use fancy images though you should keep the notions of ``closeness'' independent of which images you use.

image

Grading The design of HungryHenry calls for specific functions on lists and others forms of data (structures). Once you have a “blessed” solution to problem 1 we know that your solution must contain these functions. We will grade these functions regardless of whether you complete problem 3 or not. So turn in your signed design and your solutions regardless of how far you get.