7.4

Week 8 Set a

home work!

Programming Language ISL+

Due Date Monday 10/21 at 9:00pm (Week 8)

Purpose To further your implementation of Pacman and work with λ.

Finger Exercises

Exercise 1 From HTDP, 279 280 281

Graded Exercises

Exercise 2 Design a function using the appropriate pre-defined abstraction as well as λ which determines if every posn’s y-coordinate in a list of posns is below a given number.

Exercise 3 As it turns out, many of the pre-defined abstractions we know and love can take more than one input list, so long as the list lengths are the same and the function given can take as many arguments as there are lists. Armed with this knowledge, as well as λ, design a function hyphenate, which given two lists of strings (assumed to be of the same length), produces a list of strings, where each element is of the form "s1-s2", where "s1" is originally from the first given list and "s2" is originally from the second given list. Note this means the first element from the first list is paired with the first from the second, the second is paired with the second, etc (i.e., this is not the cartesian product).

Exercise 4 Design a function bigger-transformation, that given two [Number -> Number] functions, produces a new [Number -> Number] function whose output is the larger of the results of applying the initial functions to some input. Remember, when testing a function that produces a function, one must use the result as function equality cannot be tested! Also, be sure to use λ where appropriate.

Enter Ghost

Our poor Pacman is very lonely right now. Let’s help him out by adding his spooky and colorful friends Blinky, Pinky, Inky, and Clyde.

Given this new game component, a GameConfiguration must be updated:

; A GameConfiguration is a
;   (make-configuration Number Number Board Posn [List-of Posn] [List-of Posn] [List-of Posn])
(define-struct configuration [width height board start dots powers ghost-starts])
; Interpretation: A (make-configuration w h b s d p g) is a game
; configuration where:
; - w is the width of the board (number of cells),
; - h is the height of the board (number of cells),
; - b is the board itself (which contains information about every
;   cell on the board)
; - s is pacman's initial location (cell position),
; - d provides the locations of dots,
; - p provides the locations of power pellets,
; - g provides a list of the starting locations for ghosts.
 
; A Posn is a (make-posn Natural Natural)
; where (0, 0) is in the upper-left hand corner
 
; A Board is a [List-of Cell]
; Interpretation: A list of cells on the board.
 
; A Cell is a (make-pair Posn Walls)
; (define-struct pair [fst snd])
; Interpretation: A (make-pair p w) tracks information for a cell,
; where p represents the cell's location (cell position) and
; w represents all the walls adjacent to the cell.
 
; A Walls is a [List-of Dir]
; and represents the directions in which there are adjacent walls.
 
; A Dir is one of:
; - "up"
; - "down"
; - "left"
; - "right"

Additionally, the board file that we gave you has been updated to fit the new GameConfiguration. Here is an updated board.rkt.

Exercise 5 Incorporate the feedback you received on your last Pacman assignment; make the suggested improvements and fix any bugs that may still exist. In doing so, you will also need to go back and rewrite functions you wrote in Week 5 Set a to use appropriate list abstractions where possible.

Exercise 6 Update your data definition, examples, and tests to handle a list of ghosts. Ghosts, like Pacman, have a direction in which they are headed and occupy one tile, but also have their own color.

As your program should be run equivalently to its past iteration if no ghosts are present, all of your updated tests should pass when modified to include a list of empty ghosts. Of course, you’ll also have to add tests that involve ghosts.

Exercise 7 Update your main function to take this new type of GameConfiguration and a natural number, representing how many ghosts will be present in this iteration of the game. To match the original Pacman, we will only support up to four ghosts at a time, and each ghost should use its own distinct starting position.

You should define your own list of colors for ghosts to be, which should include four colors, one for each possible ghost. Ghosts should initially be facing upwards.

Exercise 8 Update your to-draw handler to draw the ghosts. Be sure to indicate the direction a ghost is going by where its eyes are looking.

Exercise 9 Update your on-tick handler to move ghosts. A ghost should always move in the direction it is headed in, and then change directions. A ghost should randomly choose its next direction from the possible directions it could move in, excluding the reverse of the direction it is currently facing.

In this version of the game, there will be no interactions between pacman and the ghosts. So, you do not have to check if a ghost has caught pacman.