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. 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:
  1. 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.

  2. 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.

  3. The main function calls the following functions that you must write.
    1. GetCommandLine
    2. InitCheckers
    3. PlayCheckers
    4. 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.

  4. Implement appropriate rule enforcement for our modified (kings only) checker game as listed below.
    1. 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.

  5. 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.
    1. The initial tiles may be placed anywhere on the board.
    2. Subsequent sets of tiles must intersect (overlap) an existing set of tiles. The new tile replaces the old tile at the square of intersection.
    3. All tiles specified in a single "put" command must fit on the board.

  6. Write a makefile. You can copy the file /afs/umbc.edu/users/d/e/dennis/pub/CMSC341/Proj1/Makefile and modify it as needed.

  7. 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:

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: 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.
  1. There is a lot of redundancy among game pieces.
  2. 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.
  3. Exceptions are often the appropriate method of handling errors
  4. 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

Checker Board Setup

  0123 4567
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
 

Sorry! We could not find what you were looking for

Try going back to the main page here

 
4
4
0
0
0
0