Project 3 - Connect Four with Undo
Due - Wednesday, May 17, 2006
The goal of this project is to give you an opportunity to practice
using object-oriented design and stacks. Your program should
be implemented in C++ and should use classes where appropriate.
Points will be deducted for poor design.
In this project, you will write a program that allows two users
(both human) to play a game of Connect Four. You can visit the
following website for an example of how the game works: http://www.mathsisfun.com/games/connect4.html.
The game is played using a board with 7 columns and 6 rows. Each
player is assigned a color, one player is red and one player is
black. At each turn, a player places a checker of her color in the
top empty space of one of the columns. Once a checker has been
placed, your program will check to see if a player has won the
game, or if the board is full. A player wins if four checkers of
her color are adjacent either vertically, horizontally, or
diagonally. If there is a win or tie, the program will print an
appropriate message and exit. If not, the next player takes a
turn.
Your program will represent the board using text only. For
example, your program might display:
| | | | | | | |
---------------
| | | | | | | |
---------------
| | | |R| | | |
---------------
| | | |B| | | |
---------------
| | |R|B| | | |
---------------
|B|R|B|B| | |R|
1 2 3 4 5 6 7
A user can specify where she would like to place her checker by
simply specifying the column number.
In addition to enabling standard play, your implementation must
allow the players to undo previous moves. If a player
indicates that she wishes to undo x moves, your program
will return the board to the state it was in before the previous
x moves. You must use a stack to keep track of previous
moves. In the event of an undo, pop the appropriate number of
elements from the stack and undo the move described in each
element.
Implementation Requirements and Hints
- Think carefully about the data structure you will use to
represent the board. You have several choices, but you should
be able to justify the choice you make.
- Think carefully about how you will represent a completed
move. The elements that you push on to your stack of previous
moves should contain enough information to allow you to reverse
(or undo) the move described by the element.
- Your program must use classes where appropriate. You should
have at least two classes in addition to a driver that contains
your main function. When designing your classes, think about
the objects that are used to play the game and the actions
performed with or by each object.
- If a user chooses to place a checker in a full column, an
error message should be displayed and the user should be
prompted for another selection.
Extra Credit Opportunity
For extra credit, implement a computer-based player. Your computer-based player will play against the human player by using an intelligent algorithm for determining where to play for each turn. If you wish to take advantage of this opportunity, schedule a meeting with me prior to beginning your implementation. We will discuss possible algorithms and I can give you some hints.
Due Wednesday May 17, 2006
- Complete and submit your working code.
- Make sure that each function is well documented. Your documentation should specify the type and function of the input parameters and output.
- Run your program on a variety of inputs ensuring that all error conditions are handled correctly.
Note: No portion of your code may be copied from any other
source including another text book, a web page, or another
student (current or former). You must provide citations for any
sources you have used in designing and implementing your program.
Sami Rollins