### Problem Set 8

Programming Language ISL+

Purpose This problem set concerns the design of forest-processing functions and design by iterative refinement.

Finger Exercises HtDP/2e: 262, 263, 264, 265, 267, 268, 276 (*), 279, 282, 290 (*)

Problem 1 Images in Racket are interpreted data structures. This first problem introduces a simple tree-shaped form of Image-like data. The next problem generalize this to the forms found in "2htdp/image".

Step 1 Consider the following data definition:
 (define-struct ol (over under)) (define-struct be (left right)) (define-struct al (top bottom)) ; An IG is one of: ; – an Image ; – (make-ol IG IG) ; – (make-be IG IG) ; – (make-ab IG IG)

Design the function to-image, which consumes an IG and interprets it as an image. Each occurrence of an ol structure indicates the request to use an overlay function from "2htdp/image". Hence

(make-ol (circle 10 'solid 'red) (square 30 'solid 'blue))

is interpreted as

Similarly, each occurrence of a be structure denotes a beside arrangement and an ab structure refers to an above arrangement.

Step 2 Here is a revision of the data definition:
 (define-struct ol* (base others)) (define-struct be* (base others)) (define-struct al* (base others)) ; An IG* is one of: ; – an Image ; – (make-ol* IG* [List-of IG*]) ; – (make-be* IG* [List-of IG*]) ; – (make-al* IG* [List-of IG*])
It creates a data representation that is closer to the actual *SL expressions involving these image primitives.

Design the function to-image*, which mapsIn English, the word ``map'' is used to say that a function f relates input i to output o. Hence to-image* relates an IG* to an Image. In ISL+, map refers to a specific function that has this name for historic reasons. elements of IG* to images.

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

This problem is now due at the regular time.

An alternative version of HungryHenry has several players compete to eat as many cupcakes as possible. The player who eats the most cupcakes wins. For now, Henry’s company intends to experiment with so-called random-walk players, probably to be replaced by intelligent aka human players later on.

A random walk player is assigned to a random position on the playing field and is assigned 100 randomly generated waypoints. It also receives a unique name. Like the avatar for the human player, a random-walk player travels at constant speed from its current position to its closestThe word ``closest'' is open to a misinterpretation that may affect the second stage of the project (problem 3, now move to week 9). As before, waypoints are visited in order. If a human player sets three waypoints---say A, B, and C---its avatar will visit A first, B second, and C last. In this sense, A is ``closest'' or ``next'' on the list of waypoints. This also applies to random-walk players. waypoint. When it gets close enough to a cupcake, it eats the cupcake.

The main function of this game consumes three parameters:
1. n-cc, the number of cupcakes,

2. n-rw, the number of random-walk players,

3. name, the name of the human player.

Design a data representation for the revised 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 3 Design the remaining functions from the wish list of problem 2.

Your program should render the cupcakes, distinct avatars for all players, and the to-be-visited waypoints for the human player. 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.

Grading The design of the revised HungryHenry game calls for specific functions regardless of the details of your chosen data representation. Once you have a ``blessed'' solution to problem 2 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.