Week 12 Set a
Due Date Monday, 11/18 at 9:00pm (Week 12)
Purpose Finish Pacman!
Graded Exercises
Though This Be Madness, Yet There Is Method In It
So far, our game has felt a bit haphazard, and, indeed it has been: the ghosts’ movements have been entirely random!
Below, we will specify the types of behaviors we want your game’s ghosts to follow.
All ghosts can be in one of three states: frightened, scatter, or chase. Frightened ghosts should behave exactly as frightened ghosts have in your previous iteration (randomly).
Ghosts in scatter and chase mode always have some goal, which is a position (that is possibly outside of the board). Whether the goal is constant or changing (and how) is discussed below. In the scatter and chase modes, ghosts always pick their new direction with the goal in mind. Specifically, they will pick their new direction such that taking a step in that direction will minimize the Euclidean distance to its current goal. In case of ties, ghosts prefer up over left over down over right.
Ghosts should be in scatter mode for 5 seconds, and then switch to chase mode. Ghosts should be in chase mode for 20 seconds, and then switch to scatter mode. Ghosts exiting frightened mode, whether because they were in it for 10 seconds or collided with Pacman, should enter chase mode. Ghosts should begin the game in scatter mode.
Ghosts in scatter mode always have a constant goal, whereas chase mode is more complex. A ghost’s behavior is defined by its scatter mode goal and chase mode behavior. Below, we specify four types of behavior, which your game should implement. Much like initial positions and colors, the behaviors you define should be as evenly distributed among a game’s ghosts as possible.
Blinky behavior: Blinky’s scatter goal is the top left corner, and in chase mode, its goal is Pacman’s position.
Pinky behavior: Pinky’s scatter goal is the top right corner, and in chase mode, its goal is four steps ahead of Pacman’s position, in the direction Pacman is facing.
Inky behavior: Inky’s scatter goal is the bottom left corner, and in chase mode, its goal is four steps behind Pacman’s position, in the opposite direction of the one Pacman is facing.
Clyde behavior: Clyde’s scatter goal is the bottom right corner, and in chase mode, its goal is Pacman’s position, unless it is within 8 tiles of Pacman, in which case its goal is the bottom right corner. Note that this difference is also measured with Euclidean distance.
Note For the following, you can make our lives easier by adding an "UPDATED" comment above functions, data definitions, and tests when you change your existing Pacman code and an "ADDED" comment for new parts.
Exercise 1 Update your data definitions to allow Ghosts with varied behaviors as described above. Pay careful attention to how you represent the various additional attributes, in particular how a Ghost decides where to move in pursuit of Pacman (i.e., the ghost’s behavior). Note that one of the attributes of a ghost now is the particular behavior that the ghost has.
Exercise 2 Update your examples, previously written functions, and tests to support this new representation. You may find that your tests have gotten large and difficult to understand (or worse). It might be helpful to have tests that use check-satisfied with predicates along the lines of:
; pac-at? : Number Number -> [PacmanGame -> Bool] ; is pacman at a certain position in a game? (define (pac-at? x y) ...) ; ghost-at? : Number Number -> [PacmanGame -> Bool] ; is a ghost at a certain position in a game? (define (ghost-at? x y) ...) ; ghost-in-mode? : ... -> [Ghost -> Bool] ; is a ghost in a certain mode? (define (ghost-in-mode? mode) ...) ; all-satisfy? : [X -> Bool] -> [[List-of X] -> Bool] ; do all elements of a list satisfy a predicate? (define (all-satisfy? p) ...)
Exercise 3 Implement the Ghost behaviors as described above.
For fun, not credit! After you’ve finished and turned in this assignment, you are of course welcome to implement more complex behaviors than the ones we specified if you’d like to develop "smarter" ghosts.