Project 1
Assigned |
Monday, 12 Sept 2005 |
Due |
Sunday, Sept 25, 2005 |
Updates |
12 Sept 2005
A clarification to the "put horizontal" and "put vertical"
commands was made
"print" was added to the list of valid commands found in the
file.
|
Background
Abstract Data Types (ADT) are a central idea of this course and of
object-oriented programming in general. Recall that an ADT has two parts:
(1) a description of the elements that make up the type, and (2) a
description of the operations allowed on instances of the type. The ADT
idea is implemented in C++ as a class.
The ADT is one of the most powerful and important ideas in computer
science. This project will give you some exercise in using ADTs.
Another important OOP idea, parametric polymorphism, is implemented
in C++ by templates. This project will give you some practice with C++
templates.
You will get a chance to see how exceptions can be used to handle error
situations. Since the text uses some C++ exception handling mechanisms,
this project will help you understand the text's code.
You will get a chance to review some basic C++ tasks such as handling
command-line arguments, and reading files. These
should be in your basket of programming techniques and will be important
for later projects and throughout your career.
You will write a Makefile, include headers from multiple directories,
and compile code from multiple directories. These are commonly used techniques
in industry, so they're worth learning for future reference.
You will also get a chance to think about designing computer games.
We hope this project will expose some of the underlying issues in good game
design and interest you to consider how you might make extensions to the
games.
Description
There are many board games which use a 2-dimensional array
of squares -- chess, checkers, Go, tic-tac-toe, scrabble, and chutes-and-ladders to name a few.
In chess and checkers, the board is 8 x 8. For tic-tac-toe the board is 3 x 3.
In Go, the pieces are placed at the intersections of
the lines that make up the squares. For scrabble the board is 15 x 15.
In some games, you simply place pieces on the board. In other games,
pieces are arranged in an initial starting position and then moved around
the board.
For this project, you will be designing two board games -- a modified version of checkers
and scrabble. You will not be programming complete games;
that would be too difficult a task for a short class project.
What you will be doing is providing the infrastructure, some primitive
commands and basic rule enforcement that might be used to build a complete game.
The "game board" is the fundamental data structure
A game board can be viewed as a two-dimensional array/vector of game
pieces. A board contains the pieces being played on it. We model a board as a C++ class
that has 2-dimensional array/vector to hold game pieces. The position
of each piece on the board corresponds to the indices of the array/vector. For
example, if m_board is the 2-D array/vector, then the game piece in the
r-th row and c-th column would be referenced as
m_board[r][c].
The GameBoard ADT is defined below.
Game pieces are objects, too
Checker game pieces (like chess pieces) are characterized by "color" and by "type."
They come in two colors, typically red and black but could be any colors you
wish. There are only two types of checker pieces, kings and non-kings; a
non-king can be converted into a king, but not vice-versa. Our modified version of checkers
has only "kings".
Scrabble pieces are not differentiated by color, but there are 26 types (letter tiles A - Z;
we will not use blank tiles)
There is one ADT that applies for all game pieces. It is defined
below as the GamePiece ADT.
Note that there is no implementation of the GamePiece ADT itself. Rather, it is
implemented as separate classes for
CheckerPiece and ScrabblePiece.
A game is played by sending commands to the board
To "play" the game, we must be able to perform certain primitive actions.
The actions are done by sending commands to the board. The board must
respond to the operations defined in the GameBoard ADT.
To carry out the commands, the board may send commands to one or more of its game pieces using
operations defined in the GamePiece ADT.
Game board commands are read from a file
One of the command-line arguments to the main function is the name of
a file that contains commands to be sent to the game board. The file
has one command per line.
The following commands may appear in a command file. Some commands are common
to multiple games while others are unique to a game. You must verify that
any command found in the file is appropriate for the game being played.
- move r1 c1 r2 c2 -- move the piece at row r1, column
c1 to row r2, column c2. This command could
apply to chess and checkers.
- put horizontal r c piece1 piece2 ..... -- put the specified pieces
horizontally on the board, beginning at row r, column c
and moving to the right (to higher column numbers). This command is unique to scrabble.
- put vertical r c piece1 piece2 .... -- put the specified pieces
vertically on the board, beginning at row r, column c
and moving down the board (to higher row numbers). This command is unique to scrabble.
- print -- print the contents of the board as shown in
the sample output. If the board is empty, print an appropriate message.
You may assume that all commands are well-formed, but you may not assume that
they are valid.
Project Tasks
Here are the project tasks to be done:
-
Implement C++ classes to model the game board, a checker piece and a scrabble piece.
Use appropriate header and implementation files.
Make sure your files are properly documented.
- Use the main function provided in the file
/afs/umbc.edu/users/d/e/dennis/pub/CMSC341/Proj1/Proj1.cpp
Use the function as-is, no changes. The main function
expects to be called with two command-line arguments,
namely the type of game to be played and the name of the file that
contains the commands for the game.
- The main function calls the following functions that you must write.
- GetCommandLine
- InitCheckers
- PlayCheckers
- PlayScrabble
The signature and documentation for
GetCommandLine is provided to you in
the header file /afs/umbc.edu/users/d/e/dennis/pub/CMSC341/Proj1/Proj1.h
Note: There is no need to copy Proj1.cpp or Proj1.h to your own directory.
Your makefile must access these files from the directory in which
it is provided. Do not submit Proj1.cpp or Proj1.h
The InitCheckers function takes an empty board and places the appropriate pieces on
it for the start of the game. Diagrams of the setup for a checker board is given below.
The set up for the scrabble board is simply an empty board, so no
InitScrabble function is needed.
- Implement appropriate rule enforcement for our modified (kings only) checker game
as listed below.
- Assuming that the destination square is on the board and is not occupied
a piece must move diagonally one row and one column
a piece must jump diagonally two rows and two columns. The square which is
jumped must contain a piece of the opposite color which is then removed from the board.
No multiple jumps in our game.
- Implement partial rule enforcement for scrabble. We will use a simple set of rules
dealing only with piece (tile) placement and not with actually creating words.
- The initial tiles may be placed anywhere on the board.
- Subsequent sets of tiles must intersect (overlap) an existing set of tiles.
The new tile replaces the old tile at the square of intersection.
- All tiles specified in a single "put" command must fit on the board.
- Write a makefile. You can copy the file
/afs/umbc.edu/users/d/e/dennis/pub/CMSC341/Proj1/Makefile
and modify it as needed.
-
Answer the questions posed in 341-Fall05-proj1_questions.txt. Copy the file
341-Fall05-proj1_questions.txt from the
directory
/afs/umbc.edu/users/d/e/dennis/pub/CMSC341/Proj1
to your own directory and edit it to provide your answers to
the questions. Don't forget to submit the edited file; it counts
10% toward this project's grade. Do not rename this file. It is
searched for by an automatic script. If the script can't find it, you did
not submit it properly and you will not get credit for it.
Definition of the ADTs
GameBoard
A game board is a two-dimensional array of game pieces. Each piece must be
appropriate for the board (e.g., only checker pieces on a checker board).
Each piece occupies a (row,col) position on the board. No two
pieces can occupy the same position at the same time. Rows and columns are
numbered with positive integers starting with zero; the "upper-left" corner
of the board has position (0,0).
The operations on a GameBoard are:
- PutPiece piece r c -- place
piece at row
r and column c.
It is an error to attempt to put a piece at a non-existent position
on the board or to put a piece in a non-empty position.
- RemovePiece r c
-- remove the piece that is at
row r and column
c. It is an error to attempt to remove a
piece from an empty position (one that does not have a piece on it). It is
also an error to attempt to remove a piece from a non-existent position on
the board.
- MovePiece r1 c1 r2 c2
-- move the piece that
is at row r1, column
c1 to row
r2, column c2.
It is an error to attempt to move a piece from an empty position.
It is an error to attempt to move a piece from or to a
non-existent position on the board. It is an error to move a piece to
an occupied position.
- GetPiece r c -- get the piece at
row r, column
c. It is an error to attempt to get a
piece from an empty position.
- Print(const string & title, ostream & out) const -- first prints title, then prints
the pieces on the board to out. The form of the output for a piece is determined by
operator<< defined for that piece.
GamePiece
A game piece is used to show the status of the game. There are
two kinds of game pieces, checker pieces and scrabble
pieces in this project, but this ADT could be used for other game pieces
as well. Each is defined by this
GamePiece ADT, but is implemented in its
own way. The operations allowed on a
GamePiece are:
- GetColor -- get the color of this piece.
Note that scrabble pieces do not have a color (or are all of just
one color).
- GetType -- get the type of this piece.
- Print( ostream& out ) -- Prints the game piece to the specified output stream
Additionally, there is a non-member, non-friend output operator
defined for each game piece.
A game piece is output within square brackets giving its color,
type, and position, as appropriate. See the sample output for
examples. You must use the programming idiom found on page 35 of the Weiss text
for this output operator.
Your answers to
341-Fall05-proj1_questions.txt are worth
10% of your project grade. Grammar and spelling must be correct.
You may submit a file named
grader.README if you want to leave a
message for the grader. For example, you might wish to point out some
special feature of your project that may be eligible for extra credit.
The file name must be grader.README if
the automatic script is to detect it. Any other filename for grader
comments will be ignored.
Cheating in any form will not be tolerated. Please re-read the
CMSC 341 Project Policy handout for
further details on honesty in doing projects for this course.
Thoughts for possible extra credit
Make sure you finish the required aspects of the project before attempting these extra-credit
tasks. These are just suggestions. If you have other ideas for extra-credit, great.
TAs who grade your project may award up to 10 points of extra credit.
- There is a lot of redundancy among game pieces.
- The project does not require much error checking on the command
files. What is required is that a command must be a
'move', 'put', or 'print' command and have appropriate
additional arguments.
- Exceptions are often the appropriate method of handling errors
- The position of a game piece is given by its row and column. It may
be beneficial (or just good design) to encapsulate this data into a class.
Files To Be Submitted
You should submit only the files you have written, a makefile, and the
file containing your answers to the questions. Submit all the files needed
to successfully compile your project.
Don't forget to submit
341-Fall05-proj1_questions.txt
containing your answers to the questions.
Please do not submit any of the files provided to you such as
Proj1.cpp and Proj1.h
These files, if present, will be removed by the automatic script.
Your makefile should be able to successfully compile your project in a
directory that does not contain these files.
If you have any comments for the grader, submit them in a file named
grader.README.
Submit the files using the procedure given to you for your section
of the course.
There are a number of tools available to you to check on your
submittal. It is your responsibility to ensure that the submittal is
correct and will result in a successful compilation of your project.
Do not wait till the last minute to submit your files. Give yourself
enough time to check that your submittal is correct.
If you don't submit a project correctly, you will not get credit
for it. Why throw away all that hard work you did to write the
project? Check your submittals. Make sure they work. Do this before
the due date.
Documentation for the submit program is on the web at
http://www.gl.umbc.edu/submit/.
One of the tools provided by the submit program is
submitls. It lists the names of the
files you have submitted.
Additionally, there are two programs for use only by CMSC-341 students
(not part of the UCS submit program). They are in the directory
/afs/umbc.edu/users/d/e/dennis/pub/CMSC341/
and are named submitmake and
submitrun. You can use these programs
to make or run your submitted projects.
The syntax is similar to that for submit:
submitmake <class> <project>
Example: submitmake cs341 Proj1
This makes the project, and shows you the report from the make
utility. It cleans up the directory after making the project
(removes .o files), but leaves the executable in place.
submitrun <class> <project> [command-line args]
Example: submitrun cs341 Proj1 checkers checkfile.dat
This runs the project, assuming there is an executable (i.e. submitmake
was run successfully).
Sample Output
Sample output is available in the file
/afs/umbc.edu/users/d/e/dennis/pub/CMSC341/Proj1/341-Fall05-p1-sample_output.txt
|
0 | 1 | 2 | 3 |
4 | 5 | 6 | 7 |
0 |
black | |
black | |
black | |
black | |
1 |
| black |
| black |
| black |
| black |
2 |
black | |
black | |
black | |
black | |
3 |
| | | |
| | | |
4 |
| | | |
| | | |
5 |
| red |
| red |
| red |
| red |
6 |
red | |
red | |
red | |
red | |
7 |
| red |
| red |
| red |
| red |