Assignment 1 - CS Pacman
Overview
Welcome to CS Pacman! CS Pacman is an adaptation of the 1980 maze game. In this assignment you will be implementing 1511's simplified version of this game and trying to get your Pacman to collect all the dots! Please read most of the spec before starting the assignment. (although you can save reading stages 2, 3 and 4 for later).
Assignment Structure
This assignment will test your ability to create, use and manipulate 2D arrays and structs to solve problems. To do this, the map used in the game has been implemented as a 2D array of tiles. These tiles are each represented by a struct tile
, which is outlined below:
struct tile
- Purpose:
- To store information about the tiles of the map.
- Contains:
enum entity entity
- The type of entity that exists on this tile.
- All entity types are found in the
enum entity
definition.
struct enemy enemy
- Represents the enemy at this location (if one exists).
struct enemy
- Purpose:
- To store information about a particular enemy
- Contains:
enum direction move_direction
- The direction the enemy is moving.
- All directions are found in the
enum direction
definition.
int is_present
- Represents whether the enemy is present
- You will need to add more fields to this struct in later stages.
The provided enums are quite extensive. Definitions of each are provided below:
enum entity
- Purpose:
- Represent possible entities that can exist on a tile
- Possible values:
EMPTY_ENTITY
- Represents no entity. Some tiles will have no entity present, this allows us to represent that.
WALL
- A wall that blocks the movement of Pacman and enemies
DOT
- A collectable that gives Pacman points (Stage 2)
APPLE
- A collectable that gives points, helps collect
DOT
s and can destroyWALL
s (Stage 2)
- A collectable that gives points, helps collect
BANANA
- A collectable that gives points and helps collect
DOT
s (Stage 2)
- A collectable that gives points and helps collect
POWER_UP
- A collectable that gives points and helps catch ghosts (Stage 3)
STAIRCASE_UP
- Allows Pacman to travel up to a higher floor (Stage 4)
STAIRCASE_DOWN
- Allows Pacman to travel down to a lower floor (Stage 4)
enum direction
- Purpose:
- Represent the direction of a ghost's movement
- Possible values:
UP
DOWN
LEFT
RIGHT
Program phases
There are two main phases to the overall game:
- Create level phase. This is where you will be placing Pacman and adding features to the map. This is started in Stage 1 and you will add to this throughout the rest of the assignment.
- Gameplay phase. This is where you will handle Pacman's movement throughout the level. This is started in Stage 2 and you will add to this throughout the rest of the assignment.
How To Get Started
There are a few steps to getting started with CS Pacman.
- Create a new folder for your assignment work and move into it.
mkdir ass1 cd ass1
- Download the starter code (cs_pacman.c) here or use this command on your CSE account to copy the file into your current directory:
Or, copy this code to your CSE account using the following command
1511 fetch-activity cs_pacman
- Run
1511 autotest cs_pacman
to make sure you have correctly downloaded the file.
1511 autotest cs_pacman
Read through Stage 1.
Spend a few minutes playing with the reference solution -- get a feel for how the assignment works.
1511 cs_pacman
Think about your solution, draw some diagrams, write some pseudocode to help you get started.
- Start coding!
Reference Solution
To help you understand the proper behaviour of the game, we have provided a reference implementation. If you have any questions about the behaviour of your assignment, you can check and compare it to the reference implementation.
To run the reference implementation, use the following command:
1511 cs_pacman
About the Starter Code
The provided starter code has done some setup for you. This is explained below.
Before the main function, the starter code has:
- Imported the standard input/output library.
- Defined some initial
#define
's and enums. - Defined the struct(s) described above.
In the main function, the starter code:
- Creates a 2D array of
struct tile
s calledmap
. - Initialises this
map
with some default values. - Prompts you to write your own code!
Your Tasks
This assignment consists of four stages. Each stage builds on the work of the previous stage, and each stage has a higher complexity than its predecessor. You should complete the stages in order.
A video explanation to help you get started with the assignment can here found here:
Stage 1
Stage 1.1 - Placing Pacman
Your first task for this assignment is to place our Pacman on the map! Currently, the starter code creates a 2D array of struct tiles
, and initialises them with the initialise_map()
function that we’ve provided.
Your program should scan in the coordinates (first row, then column) at which Pacman should be placed. The updated map should then be printed out, using the provided print_map()
function.
Assumptions / Restrictions / Clarifications
- You can assume that you will always be provided with two integers for the row and column for Pacman.
- The row/column provided will always fall within the map.
Examples
Autotest
Stage 1.2 - Adding Features
Now that we’ve placed Pacman, we also need to place some features on the map! At this stage, the only feature that your program should handle is placing walls — but you will need to extend this to other features in later stages, so have a think about how best to do that!
To add features, your program should read characters in a loop, followed by a variable number of inputs based on which feature is being added. The loop should terminate when the user enters the 'S'
character (meaning “Start the game”).
As mentioned, the only feature for this stage is the placement of walls. To place a wall, the user will first type the character 'W'
, followed by the wall’s start and end coordinates (first row, then column).
... Create the level: W [start_row] [start_col] [end_row] [end_col] ...
For this stage, you can assume that the walls will either be horizontal or vertical, and that the start
values will be less than or equal to their end
counterparts. In other words, every coordinate pair received will have either the row OR column equal, and go from left to right, or top to bottom.
In this stage, every wall entered will be valid — meaning that all walls will fall entirely within the map.
Once all of the walls have been placed, the map should be printed.
Assumptions / Restrictions / Clarifications
- You can assume that input for this stage will always end with
S
. - In this stage, all walls entered will be horizontal or vertical (for each coordinate pair, either the column will be the same, or the row will be the same).
- In this stage, you will not be given walls that fall outside the map.
- You can assume that
start_row
will always be less than or equal toend_row
. - You can assume that
start_col
will always be less than or equal toend_col
. - A wall could be a single block (
start_row
equalsend_row
andstart_col
equalsend_col
)
Examples
Autotest
1511 autotest-stage 01_02 cs_pacman
Stage 1.3 - Validating Walls
In this stage, the walls given may not be horizontal or vertical, and thus unable to be placed. If this occurs, the error message "Given wall is not horizontal or vertical!"
should be printed, and the program should continue reading input.
We also need to handle the case where some or all of the wall falls outside the map. If part or all of a wall lies out of the map, then that part should be ignored. The part of the wall that lies within the map should still be placed.
Assumptions / Restrictions / Clarifications
- You can still assume that you receive a valid number of inputs.
- You can still assume that
start_row
will always be less than or equal toend_row
. - You can still assume that
start_col
will always be less than or equal toend_col
. - If a wall is not horizontal/vertical AND falls outside of the map completely, you should still print
"Given wall is not horizontal or vertical!"
Examples
Autotest
1511 autotest-stage 01_03 cs_pacman
Stage 1.4 - Placing Dots
Once the setup phase has finished, and all features have been placed, we need to fill all the remaining squares with dots. These are the points which Pacman will collect while moving around the map. Any square which does not already have an entity on it should have a dot placed on it.
Assumptions / Restrictions / Clarifications
- Dots should not be placed on tiles with another entity already present.
- A dot should be placed under Pacman
Examples
Autotest
1511 autotest-stage 01_04 cs_pacman
Testing and Submission
Remember to do your own testing
Are you finished with this stage? If so, you should make sure to do the following:
- Run
1511 style
, and clean up any issues a human may have reading your code. Don't forget -- 20% of your mark in the assignment is based on style and readability! - Autotest for this stage of the assignment by running the
autotest-stage
command as shown below. - Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1511 style cs_pacman.c 1511 autotest-stage 01 cs_pacman give cs1511 ass1_cs_pacman cs_pacman.c