Milestone 1: Due Thursday, Nov 29th by 11:59 PM

Milestone 2: Due Thursday, Dec 6th by 11:59 PM

Getting Started

Start by downloading CS101_Assign06.zip, saving it in the directory H:\CS101.

Start a Cygwin Bash Shell and run the following commands:

cd h:
cd CS101
unzip CS101_Assign06.zip
cd CS101_Assign06

Using Notepad++, open the files

H:\CS101\CS101_Assign06\Scene.h

H:\CS101\CS101_Assign06\Scene.cpp

H:\CS101\CS101_Assign06\Player.h

H:\CS101\CS101_Assign06\Player.cpp

You will add your code to these files. Note: we will be using separate files for the game play, scene structure, and player structures.

The file Chomp.cpp contains the provided game loop, and the file Const.h includes symbolic constants to use throughout the program. You should not need to modify either of these files.

A sample Windows executable is included in the .zip file and can be run in Cygwin by

./ChompSolWin

or for Linux in a terminal window

./ChompSolLinux

(there is also a sample executable compiled for Mac as ChompSolMac but it may be a bit erratic).

When you are ready to compile the program, in the Cygwin window type the command

make

To run the program, in the Cygwin window type the command

./Chomp.exe

Your Task

Since many of you have either played or at least seen the retro arcade game Pacman, the purpose of this assignment is to write a similar game using terminal graphics. The object of the game is to move your player around a board collecting pellets and power-ups while avoiding the 4 ghosts.

Initializing the Board

Code has been provided to load in the game board and display it on the screen.

The following fields are defined in the Scene structure (in Scene.h)

Loading in the board

The layout of the board is included in the text file board.txt where + indicates walls, . indicates pellets, and O indicates power ups.

The initialize_Scene() function takes a Scene structure as a reference parameter. The function calls load_Board() passing the board, number of pellets, and number of powerup fields by reference. load_board() reads the file and initializes a 2D board array parameter with the objects at each board location. Each element of the array will contain a symbolic constant for the object at that location as either:

The function will also return the number of pellets (num_pellets) and number of power-ups (num_powerups) the board contains through reference parameters.

initialize_Scene() will be modified in the milestones to perform other initializations for the player and ghosts.

Drawing the board

The render_Scene() function then takes a Scene as a reference parameter and calls the draw_Board() function passing the board field from the Scene *s parameter.

The draw_Board() function takes a 2D array of int’s representing the board and renders the board on the screen. Symbolic constants have been defined for the characters to render as:

You should see something like this when you run the program:

image

Milestone 1

Milestone 1 will add the player and allow them to move around the board.

You will need to first create a structure named Player and then add the following fields to the Player structure (in Player.h)

Player functions

We will need to add functions to initialize, draw and update the fields of the player.

Scene functions

Next we need to incorporate the player into the scene.

At this point you should be able to move the player around the board “gobbling” up the pellets and power-ups.

Milestone 2

Milestone 2 incorporates the ghosts to complete the game play. The ghosts will simply be represented by an array of Player’s that uses a different function to determine their desired velocities (basic AI).

You will need to first add a field to the Scene structure (in Scene.h)

and the Player structure (in Player.h)

Player functions

Note the draw_Player(), check_Player_Move(), and update_Player() functions can be used for both the user and ghosts without modification.

Scene functions

At this point you will have a playable game, but the ghosts will move extremely fast (although not very intelligently). To make the ghosts move at a more reasonable speed, determine a way to only update them every GHOST_DELAY (another constant in Const.h) update cycles. Hint: consider adding a counter field to the Scene structure and checking it in update_Scene().

Grading

Your grade will be determined as follows:

Milestone 1 - 75 points

Milestone 2 - 75 points

We expect you to use good coding style. Points may be deducted for poor variable names, inconsistent or missing indentation, and/or lack of comments.

Extra Credit - 45 points

Improve the ghost AI - 10 points

One drastic improvement that can be made to the ghost AI is rather than select a random direction to attempt to move (which often results in moving into a wall), select only from the valid directions the ghost can move (with a strong preference to continue moving forward, a lesser preference to turn if possible, and with a relatively small preference to turn around). This will make the ghost movement appear much smoother (and smarter). Additionally the ghost’s prefered direction can be further biased towards the player if they are within a certain range of the player (basically providing a “chase” mode when they are close). There should be a small probability that the ghost will stop chasing otherwise the game will become very difficult to play (the ghosts will essentially ambush the player pinning him in a corner).

Additional levels - 10 points

Alternate levels can be designed using the same symbols as board.txt, i.e. + for walls, . for pellets, O for power-ups, and blanks for empty locations. Make sure your boards are 28 characters wide by 22 characters high (to match the board array used in the load_Board() function). Be careful if you choose to use tunnels that they are at row TUNNEL_Y otherwise you will need to modify the check_Player_Move() function. Once a level is completed, load and begin another level.

Capturable ghosts - 25 points

Probably the most complicated improvement (in the spirit of the original video game) is to allow the ghosts to be “captured” for a brief period of time after the player “eats” a power-up. If the player and ghost are at the same location during this time, the player earns extra points and the ghost is returned to its home location while no longer being capturable. The player should receive some type of warning that the capturable time is about to expire. In the original game, the ghosts would turn blue while they were capturable and flash when they were about to become non-capturable. Consider adding flags to the Player structure that tracks the state of each ghost and a counter to the Scene structure that is set to a value and counts down whenever a power-up is eaten (and can be used to determine when to make the ghosts “flash”).

Program structure

Note: The board size is set by the symbolic constants WIDTH (=28) and HEIGHT (=22) which can be used when accessing the elements of the 2D array.

The overall layout of the program can be graphically illustrated by the following flowchart showing the relationships between the functions and which files they should be placed in:

image

Submitting

To submit your code, make sure all the files are saved, and in the Cygwin window type one of the following commands (depending on whether you are submitting Milestone 1 or Milestone 2).

For Milestone 1:

make submit_ms1

File Milestone 2:

make submit_ms2

Enter your Marmoset username and password (which you should have received by email.) Note that your password will not be echoed to the screen. Make sure that after you enter your username and password, you see a message indicating that the submission was successful.

If the make commands above do not work, you can submit using the web interface (see the link for details).

Make sure that you check the file(s) you submitted to ensure that they are correct. See the instructions for Verifying your submission.