CSCE 2004 - Homework 5
Due Date - Nov 10, 2014 at 11:59 PM

10% off if handed in by Nov 11, 2014 at 11:59 PM
20% off if handed in by Nov 12, 2014 at 11:59 PM
30% off if handed in by Nov 13, 2014 at 11:59 PM
No credit if handed in after Nov 13, 2014

1. Problem Statement:

The primary goal of this programming assignment is to give students experience with two-dimensional arrays in C++. To do this we will be implementing a simple game called "Keep Away Chess". This game is played on a standard 8x8 chess board. The object is for two players to take turns putting pieces on the board so they can not be taken by any other piece. The first person who places a piece on the board that can be taken by another piece loses the game.

To start off, your program should ask the user if they want to play keep away with Rooks (which move horizontally and vertically) or Bishops (which move diagonally). Then your program should take turns prompting player1 and player2 asking them where they want to place their piece, adding their piece to the chess board, and then checking to see if the player has lost. For example, here is a portion of a game played with Rooks where player 2 loses. For a longer example see hw5.txt.

+---+---+---+---+---+---+---+---+
| R |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+
|   |   |   |   |   | R |   |   |
+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   | R |   |
+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+

 - Player 2 -
Enter row [0..7]: 2
Enter col [0..7]: 5

+---+---+---+---+---+---+---+---+
| R |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+
|   |   |   |   |   | X |   |   |
+---+---+---+---+---+---+---+---+
|   |   |   |   |   | R |   |   |
+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   | R |   |
+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+

Sorry, you lose

Students are allowed to use any combination of C++ features we have discussed in class or lab. You are not required or allowed to look ahead to more advanced C++ features like classes to perform this task.

2. Design:

This game is pretty trivial to play in real life but it is tricky to design and implement correctly. Clearly you will need to store the contents of the chess board in a two-dimensional array. You will have to check that the coordinates the player enters are within the [0..7] range before you access this array or you will have an "array bounds error" and your program may die.

Checking to see if the player has lost the game is probably the most difficult problem you need to solve. In the case of Rooks, you will need to check the board along rows and columns to see if the new piece can take one of the previous pieces placed on the board. In the case of Bishops you will need to check the diagonals. This will require some careful thinking to design the correct loops. In both cases, you need to be careful not to go outside the bounds of the 8x8 chess board.

This program is large enough and complex enough that it makes sense to break it into smaller pieces and implement these as functions. For example, a function to print the board, a function to read user input, etc. This will give you a chance to implement and debug these functions separately before you put them together in the final game.

3. Implementation:

Since you are starting with a "blank piece of paper" to implement this project, it is very important to develop your code incrementally writing comments, adding code, compiling, debugging, a little bit at a time. This way, you always have a program that "does something" even if it is not complete.

Remember to use good programming style when creating your program -- good names for variables and constants, proper indenting for loops and conditionals, clear comments, etc. Also, be sure to save backup copies of your program somewhere safe. Otherwise, you may end up retyping your whole program if something goes wrong.

4. Testing:

Test your program to check that it operates correctly for all of the requirements listed above. Also check for the error handling capabilities of the code. Try your program with several input values, and save your testing output in text files for inclusion in your project report.

5. Documentation:

When you have completed your C++ program, write a short report using the project report template describing what the objectives were, what you did, and the status of the program. Does it work properly for all test cases? Are there any known problems? Save this report to be submitted electronically.

6. Project Submission:

In this class, we will be using electronic project submission to make sure that all students hand their programming projects and labs on time, and to perform automatic analysis of all programs that are submitted.

Rename your program and documentation files 123456789.hw5.cpp and 123456789.hw5.docx using your UAID number in place of 123456789, and go the Blackboard site for this class and submit these two files.

The dates on your electronic submission will be used to verify that you met the due date above. All late projects will receive reduced credit:

You will receive partial credit for all programs that compile even if they do not meet all program requirements, so handing projects in on time is highly recommended.

7. Academic Honesty Statement:

  • Students are expected to submit their own work on all programming projects, unless group projects have been explicitly assigned.
  • Students are NOT allowed to distribute code to each other, or copy code from another individual or website.
  • Students ARE allowed to use any materials on the class website, or in the textbook, or ask the instructor and/or GTAs for assistance.
  • This course will be using highly effective program comparison software to calculate the similarity of all programs to each other, and to homework assignments from previous semesters. Please do not be tempted to plagiarize from another student.

    Violations of the policies above will be reported to the Provost's office and may result in a ZERO on the programming project, an F in the class, or suspension from the university, depending on the severity of the violation and any history of prior violations.